summaryrefslogtreecommitdiff
path: root/sys/lib
diff options
context:
space:
mode:
authorMichael Shalayeff <mickey@cvs.openbsd.org>1996-10-16 11:32:09 +0000
committerMichael Shalayeff <mickey@cvs.openbsd.org>1996-10-16 11:32:09 +0000
commitebea7bfd3afa1f7591a977db1b64d0c4aa366df4 (patch)
treeab8bb3b42b5da31a86eb1fbf6a113452b8130cd3 /sys/lib
parent3addbdbee7f30b53337980fb4fb2b401702e20dd (diff)
add functions.
remove functions. optimize (: emulate b{copy,cmp,zero} through the mem{cpy,cmp,set}. add useful macros to stand.h
Diffstat (limited to 'sys/lib')
-rw-r--r--sys/lib/libsa/memcmp.c (renamed from sys/lib/libsa/bcopy.c)47
-rw-r--r--sys/lib/libsa/memcpy.c20
-rw-r--r--sys/lib/libsa/stand.h23
-rw-r--r--sys/lib/libsa/strcmp.c13
-rw-r--r--sys/lib/libsa/strncpy.c48
5 files changed, 107 insertions, 44 deletions
diff --git a/sys/lib/libsa/bcopy.c b/sys/lib/libsa/memcmp.c
index 62b9d6b3171..babeac9c91f 100644
--- a/sys/lib/libsa/bcopy.c
+++ b/sys/lib/libsa/memcmp.c
@@ -1,9 +1,8 @@
-/* $OpenBSD: bcopy.c,v 1.4 1996/09/23 14:18:47 mickey Exp $ */
-/* $NetBSD: bcopy.c,v 1.5 1995/04/22 13:46:50 cgd Exp $ */
+/* $OpenBSD: memcmp.c,v 1.1 1996/10/16 11:32:06 mickey Exp $ */
/*-
- * Copyright (c) 1993
- * The Regents of the University of California. All rights reserved.
+ * Copyright (c) 1996 Michael Shalayeff
+ * All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -15,15 +14,13 @@
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
+ * This product includes software developed by Michael Shalayeff.
+ * 4. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
*
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
@@ -33,30 +30,18 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * @(#)bcopy.c 8.1 (Berkeley) 6/11/93
*/
#include <sys/types.h>
#include "stand.h"
-/*
- * This is designed to be small, not fast.
- */
-void
-bcopy(s1, s2, n)
+int
+memcmp(s1, s2, n)
const void *s1;
- void *s2;
- size_t n;
+ const void *s2;
+ size_t n;
{
- register const char *f = s1;
- register char *t = s2;
-
- if (f < t) {
- f += n;
- t += n;
- while (n-- > 0)
- *--t = *--f;
- } else
- while (n-- > 0)
- *t++ = *f++;
+ while(n-- && *(char*)s1 == *(char*)s2)
+ ((char*)s1)++, ((char*)s2)++;
+ return *(char*)s1 - *(char*)s2;
}
diff --git a/sys/lib/libsa/memcpy.c b/sys/lib/libsa/memcpy.c
index e6fed9ddbe0..3a2b2756bf8 100644
--- a/sys/lib/libsa/memcpy.c
+++ b/sys/lib/libsa/memcpy.c
@@ -1,4 +1,5 @@
-/* $OpenBSD: memcpy.c,v 1.2 1996/09/23 14:18:57 mickey Exp $ */
+/* $OpenBSD: memcpy.c,v 1.3 1996/10/16 11:32:07 mickey Exp $ */
+/* $NetBSD: bcopy.c,v 1.5 1995/04/22 13:46:50 cgd Exp $ */
/*-
* Copyright (c) 1993
@@ -32,18 +33,31 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * from: @(#)bcopy.c 8.1 (Berkeley) 6/11/93
+ * @(#)bcopy.c 8.1 (Berkeley) 6/11/93
*/
#include <sys/types.h>
#include "stand.h"
+/*
+ * This is designed to be small, not fast.
+ */
void *
memcpy(s1, s2, n)
void *s1;
const void *s2;
size_t n;
{
- bcopy(s2, s1, n);
+ register const char *f = s2;
+ register char *t = s1;
+
+ if (f < t) {
+ f += n;
+ t += n;
+ while (n-- > 0)
+ *--t = *--f;
+ } else
+ while (n-- > 0)
+ *t++ = *f++;
return s1;
}
diff --git a/sys/lib/libsa/stand.h b/sys/lib/libsa/stand.h
index 40ea1883785..7514d83c0c8 100644
--- a/sys/lib/libsa/stand.h
+++ b/sys/lib/libsa/stand.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: stand.h,v 1.8 1996/10/15 09:58:40 mickey Exp $ */
+/* $OpenBSD: stand.h,v 1.9 1996/10/16 11:32:08 mickey Exp $ */
/* $NetBSD: stand.h,v 1.13 1996/01/13 22:25:42 leo Exp $ */
/*-
@@ -50,6 +50,13 @@
struct open_file;
/*
+ * Useful macros
+ */
+#define NENTS(x) sizeof(x)/sizeof(x[0])
+#define max(a,b) (((a)>(b))? (a) : (b))
+#define min(a,b) (((a)>(b))? (b) : (a))
+
+/*
* This structure is used to define file system operations in a file system
* independent way.
*/
@@ -62,6 +69,7 @@ struct fs_ops {
size_t size, size_t *resid));
off_t (*seek) __P((struct open_file *f, off_t offset, int where));
int (*stat) __P((struct open_file *f, struct stat *sb));
+ int (*readdir) __P((struct open_file *f, char *));
};
extern struct fs_ops file_system[];
@@ -125,10 +133,16 @@ void twiddle __P((void));
void gets __P((char *));
__dead void panic __P((const char *, ...)) __attribute__((noreturn));
__dead void _rtt __P((void)) __attribute__((noreturn));
-void bcopy __P((const void *, void *, size_t));
+#define bzero(s,n) ((void)memset((s),0,(n)))
+#define bcmp(s1,s2,n) (memcmp((s2),(s1),(n)))
+#define bcopy(s1,s2,n) ((void)memcpy((s2),(s1),(n)))
void *memcpy __P((void *, const void *, size_t));
+int memcmp __P((const void *, const void*, size_t));
+char *strncpy __P((char *, const char *, size_t));
+char *strcpy __P((char *, const char *));
void *memset __P((void *, int, size_t));
-void exec __P((char *, char *, int));
+void exec __P((char *, void *, int));
+void execz __P((void *, void *, int));
int open __P((const char *, int));
int close __P((int));
void closeall __P((void));
@@ -148,8 +162,11 @@ ssize_t null_write __P((struct open_file *f, void *buf,
size_t size, size_t *resid));
off_t null_seek __P((struct open_file *f, off_t offset, int where));
int null_stat __P((struct open_file *f, struct stat *sb));
+int null_readdir __P((struct open_file *f, char *name));
/* Machine dependent functions */
void machdep_start __P((char *, int, char *, char *, char *));
int getchar __P((void));
void putchar __P((int));
+time_t getsecs __P((void));
+
diff --git a/sys/lib/libsa/strcmp.c b/sys/lib/libsa/strcmp.c
index 11a80b5b35b..ac5a812aa37 100644
--- a/sys/lib/libsa/strcmp.c
+++ b/sys/lib/libsa/strcmp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: strcmp.c,v 1.1 1996/09/18 13:56:08 mickey Exp $ */
+/* $OpenBSD: strcmp.c,v 1.2 1996/10/16 11:32:07 mickey Exp $ */
/*-
* Copyright (c) 1996 Michael Shalayeff
@@ -37,11 +37,10 @@
int
strcmp(s1, s2)
- const char *s1;
- const char *s2;
+ register const char *s1;
+ register const char *s2;
{
- register int i = 0, j = 0;
- while(s1[i] && s2[j] && (s1[i] != s2[j]) != 0)
- i++, j++;
- return s1[i] - s2[j];
+ while(*s1 && *s2 && *s1 == *s2)
+ s1++, s2++;
+ return *s1 - *s2;
}
diff --git a/sys/lib/libsa/strncpy.c b/sys/lib/libsa/strncpy.c
new file mode 100644
index 00000000000..2f09aeb2127
--- /dev/null
+++ b/sys/lib/libsa/strncpy.c
@@ -0,0 +1,48 @@
+/* $OpenBSD: strncpy.c,v 1.1 1996/10/16 11:32:07 mickey Exp $ */
+
+/*-
+ * Copyright (c) 1996 Michael Shalayeff
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by Michael Shalayeff.
+ * 4. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+#include <sys/types.h>
+#include "stand.h"
+
+char *
+strncpy(s1, s2, n)
+ char *s1;
+ const char *s2;
+ size_t n;
+{
+ char *p = s1;
+ while(n-- && (*s1++ = *s2++) != '\0')
+ ;
+ return p;
+}