Browse Source

Lots and lots of cleanups.
-Erik

Eric Andersen 24 years ago
parent
commit
a67c627325

+ 4 - 4
include/resolv.h

@@ -55,13 +55,13 @@ int encode_answer(struct resolv_answer * a,
 	unsigned char * dest, int maxlen);
 int decode_answer(unsigned char * message, int offset,
 	struct resolv_answer * a);
-char * resolve_name(const char * name, int mailbox);
+const char * resolve_name(const char * name, int mailbox);
 
 int encode_packet(struct resolv_header * h,
 	struct resolv_question ** q,
-	struct resolv_question ** an,
-	struct resolv_question ** ns,
-	struct resolv_question ** ar,
+	struct resolv_answer ** an,
+	struct resolv_answer ** ns,
+	struct resolv_answer ** ar,
 	unsigned char * dest, int maxlen);
 int decode_packet(unsigned char * data, struct resolv_header * h);
 

+ 5 - 0
include/stdio.h

@@ -3,6 +3,7 @@
 #define __STDIO_H
 
 #include <features.h>
+#include <stdarg.h>
 #include <sys/types.h>
 
 #ifndef SEEK_SET
@@ -197,5 +198,9 @@ extern int vfscanf __P ((FILE *__restrict __s,
      __attribute__ ((__format__ (__scanf__, 2, 0)));
 
 
+/* Print a message describing the meaning of the value of errno.  */
+extern void perror __P ((__const char *__s));
+
+
 
 #endif /* __STDIO_H */

+ 3 - 0
include/stdlib.h

@@ -68,6 +68,9 @@ extern char * gcvt __P ((float number, size_t ndigit, char * buf));
 #define atof(x) strtod((x),(char**)0)
 #define atoi(x) (int)strtol((x),(char**)0,10)
 #define atol(x) strtol((x),(char**)0,10)
+#ifdef __LIBC__
+char* itoa(int i);
+#endif
 
 /* Returned by `div'.  */
 typedef struct

+ 19 - 34
include/unistd.h

@@ -36,6 +36,10 @@ extern int symlink __P ((__const char *__from, __const char *__to));
 extern int readlink __P ((__const char *__path, char *__buf, size_t __len));
 extern int unlink __P ((__const char *__name));
 extern char *getcwd __P ((char *__buf, size_t __size));
+/* Duplicate FD, returning a new file descriptor on the same file.  */
+extern int dup __P ((int __fd));
+/* Duplicate FD to FD2, closing FD2 and making it open on the same file.  */
+extern int dup2 __P ((int __fd, int __fd2));
 extern int fchdir __P ((int __fd));
 extern int chdir __P ((__const char *__path));
 extern int chown __P ((__const char *__file,
@@ -90,44 +94,25 @@ extern int execve __P ((__const char *__path, char *__const __argv[],
 extern int execvp __P ((__const char *__file, char *__const __argv[]));
 
 
+/* Execute PATH with arguments ARGV and environment ENVP. */
+extern int execvep __P ((__const char *path, char *__const __argv[], 
+	    char *__const __envp[]));
 
+/* Terminate program execution with the low-order 8 bits of STATUS.  */
+extern void _exit __P ((int __status)) __attribute__ ((__noreturn__));
 
+/* Clone the calling process, creating an exact copy.
+ *    Return -1 for errors, 0 to the new process,
+ *       and the process ID of the new process to the old process.  */
+extern __pid_t __fork __P ((void));
+extern __pid_t fork __P ((void));
 
-#if 0                                                                         
-#ifndef SYS_fork
-#define SYS_fork 2
-#endif
-
-#define vfork() ({ \
-register long __res __asm__ ("%d0"); \
-__asm__ __volatile__ ("trap  #0" \
-                      : "=g" (__res) \
-                      : "0" (SYS_fork) \
-                      : "%d0"); \
-__res; \
-})
-#endif
-
-#ifdef __mc68000__
-
-#define vfork() ({						\
-register unsigned long __res __asm__ ("%d0") = __NR_fork;	\
-__asm__ __volatile__ ("trap  #0"				\
-                      : "=g" (__res)				\
-                      : "0" (__res)				\
-                      : "%d0");					\
-if (__res >= (unsigned long)-4096) {				\
-	errno = -__res;						\
-	__res = (pid_t)-1;					\
-}								\
-(pid_t)__res;							\
-})
-
-
+/* Clone the calling process, but without copying the whole address space.
+ *    The calling process is suspended until the new process exits or is
+ *       replaced by a call to `execve'.  Return -1 for errors, 0 to the new process,
+ *          and the process ID of the new process to the old process.  */
+extern __pid_t vfork __P ((void));
 
-#define fork fork_not_available_use_vfork
-#define clone clone_not_available_use__clone
-#endif		
 
 #ifndef SEEK_SET
 #define SEEK_SET 0

+ 1 - 0
libc/inet/addr.c

@@ -7,6 +7,7 @@
 #include <ctype.h>
 #include <netinet/in.h>
 
+int inet_aton(const char *cp, struct in_addr *inp);
 
 #ifdef L_inet_aton
 int

+ 8 - 8
libc/inet/resolv.c

@@ -312,9 +312,9 @@ int decode_answer(unsigned char * message, int offset,
 #ifdef L_encodep
 int encode_packet(struct resolv_header * h,
 	struct resolv_question ** q,
-	struct resolv_question ** an,
-	struct resolv_question ** ns,
-	struct resolv_question ** ar,
+	struct resolv_answer ** an,
+	struct resolv_answer ** ns,
+	struct resolv_answer ** ar,
 	unsigned char * dest, int maxlen)
 {
 	int i, total=0;
@@ -694,12 +694,12 @@ int resolve_mailbox(const char * address,
 #endif
 
 extern int nameservers;
-extern const char * nameserver[3];
+extern const char *__const nameserver[3];
 
 #ifdef L_opennameservers
 
 int nameservers;
-const char * nameserver[3];
+const char *__const nameserver[3];
 
 int open_nameservers()
 {
@@ -707,8 +707,8 @@ int open_nameservers()
 	char **arg;
 	int i;
 
-	if (fp = fopen("/etc/resolv.conf", "r")) {
-		if (arg = cfgfind(fp, "nameserver")) {
+	if ((fp = fopen("/etc/resolv.conf", "r"))) {
+		if ((arg = cfgfind(fp, "nameserver"))) {
 			for (i=1; arg[i]; i++) {
 				nameserver[nameservers++] = strdup(arg[i]);
 			}
@@ -730,7 +730,7 @@ void close_nameservers(void) {
 
 #ifdef L_resolvename
 
-char * resolve_name(const char * name, int mailbox)
+const char * resolve_name(const char * name, int mailbox)
 {
 	struct in_addr in;
 	int i;

+ 1 - 1
libc/pwd_grp/pwent.c

@@ -54,7 +54,7 @@ struct passwd *
 getpwent(void)
 {
   if (pw_fd!=-1)
-    return __getpwent(pw_fd);
+    return (__getpwent(pw_fd));
   return NULL;  
 }
 

+ 27 - 27
libc/stdio/scanf.c

@@ -1,3 +1,5 @@
+#include <stdlib.h>
+#include <unistd.h>
 #include <stdio.h>
 #include <ctype.h>
 #include <string.h>
@@ -30,27 +32,27 @@ va_dcl
 
 #ifdef L_sscanf
 #ifdef __STDC__
-int sscanf(char * sp, const char * fmt, ...)
+int sscanf(const char * sp, const char * fmt, ...)
 #else
 int sscanf(sp, fmt, va_alist)
-char * sp;
+__const char * sp;
 __const char *fmt;
 va_dcl
 #endif
 {
-static FILE  string[1] =
-{
-   {0, (char*)(unsigned) -1, 0, 0, (char*) (unsigned) -1, -1,
-    _IOFBF | __MODE_READ}
-};
-
-  va_list ptr;
-  int rv;
-  va_strt(ptr, fmt);
-  string->bufpos = sp;
-  rv = vfscanf(string,fmt,ptr);
-  va_end(ptr);
-  return rv;
+    FILE  string[1] =
+    {
+	{0, (char*)(unsigned) -1, 0, 0, (char*) (unsigned) -1, -1,
+	    _IOFBF | __MODE_READ}
+    };
+
+    va_list ptr;
+    int rv;
+    va_strt(ptr, fmt);
+    string->bufpos = (unsigned char *)((void*)sp);
+    rv = vfscanf(string,fmt,ptr);
+    va_end(ptr);
+    return rv;
 }
 #endif
 
@@ -83,18 +85,16 @@ va_list ap;
 #endif
 
 #ifdef L_vsscanf
-int vsscanf(sp, fmt, ap)
-char * sp;
-__const char *fmt;
+int vsscanf(__const char *sp, __const char *fmt, va_list ap)
 {
-static FILE  string[1] =
-{
-   {0, (char*)(unsigned) -1, 0, 0, (char*) (unsigned) -1, -1,
-    _IOFBF | __MODE_READ}
-};
-
-  string->bufpos = sp;
-  return vfscanf(string,fmt,ap);
+    FILE  string[1] =
+    {
+	{0, (char*)(unsigned) -1, 0, 0, (char*) (unsigned) -1, -1,
+	    _IOFBF | __MODE_READ}
+    };
+
+    string->bufpos = (unsigned char *)((void*)sp);
+    return vfscanf(string,fmt,ap);
 }
 #endif
 
@@ -170,7 +170,7 @@ int fp_sval[NSTATE] = {
 int
 vfscanf(fp, fmt, ap)
 register FILE *fp;
-register char *fmt;
+register const char *fmt;
 va_list ap;
 
 {

+ 30 - 26
libc/stdio/stdio.c

@@ -6,15 +6,19 @@
 /* This is an implementation of the C standard IO package.
  */
 
+#include <stdlib.h>
 #include <stdio.h>
-
+#include <unistd.h>
 #include <fcntl.h>
 #include <sys/types.h>
 #include <malloc.h>
 #include <errno.h>
+#include <string.h>
 
 #undef STUB_FWRITE
 
+void __io_init_vars(void);
+
 extern FILE *__IO_list;		/* For fflush at exit */
 
 #define FIXED_BUFFERS 2
@@ -80,10 +84,7 @@ FILE  stderr[1] =
 
 /* Call the stdio initiliser; it's main job it to call atexit */
 
-#define STATIC
-
-STATIC int 
-__stdio_close_all()
+void __stdio_close_all(void)
 {
    FILE *fp;
    fflush(stdout);
@@ -103,8 +104,7 @@ static int first_time = 0;
 struct fixed_buffer _fixed_buffers[2];
 
 
-STATIC void 
-__io_init_vars()
+void __io_init_vars(void)
 {
    if( first_time ) return;
    first_time = 1;
@@ -206,7 +206,9 @@ FILE *fp;
    if (fp->mode & __MODE_WRITING)
       fflush(fp);
 
+#if __MODE_IOTRAN
  try_again:
+#endif
    /* Can't read or there's been an EOF or error then return EOF */
    if ((fp->mode & (__MODE_READ | __MODE_EOF | __MODE_ERR)) != __MODE_READ)
       return EOF;
@@ -319,7 +321,7 @@ FILE *fp;
 char *
 fgets(s, count, f)
 char *s;
-size_t count;
+int count;
 FILE *f;
 {
    char *ret;
@@ -368,7 +370,7 @@ char *str;
 #ifdef L_fputs
 int
 fputs(str, fp)
-char *str;
+const char *str;
 FILE *fp;
 {
    register int n = 0;
@@ -385,7 +387,7 @@ FILE *fp;
 #ifdef L_puts
 int
 puts(str)
-char *str;
+const char *str;
 {
    register int n;
 
@@ -405,12 +407,12 @@ char *str;
  * This ignores __MODE__IOTRAN; probably exactly what you want. (It _is_ what
  * fgetc wants)
  */
-int
+size_t
 fread(buf, size, nelm, fp)
-char *buf;
-int   size;
-int   nelm;
-FILE *fp;
+void	*buf;
+size_t  size;
+size_t  nelm;
+FILE	*fp;
 {
    int   len, v;
    unsigned bytes, got = 0;
@@ -467,12 +469,12 @@ FILE *fp;
  * 
  * Again this ignores __MODE__IOTRAN.
  */
-int
+size_t
 fwrite(buf, size, nelm, fp)
-char *buf;
-int   size;
-int   nelm;
-FILE *fp;
+const void *buf;
+size_t  size;
+size_t  nelm;
+FILE	*fp;
 {
    register int v;
    int   len;
@@ -606,7 +608,6 @@ int   ref;
 long ftell(fp)
 FILE * fp;
 {
-   long rv;
    if (fflush(fp) == EOF)
       return EOF;
    return lseek(fp->fd, 0L, SEEK_CUR);
@@ -620,10 +621,10 @@ FILE * fp;
  */
 FILE *
 __fopen(fname, fd, fp, mode)
-char *fname;
+const char *fname;
 int   fd;
 FILE *fp;
-char *mode;
+const char *mode;
 {
    int   open_mode = 0;
 #if __MODE_IOTRAN
@@ -875,8 +876,8 @@ size_t size;
 
    if( mode == _IOFBF || mode == _IOLBF )
    {
-      if( size <= 0  ) size = BUFSIZ;
-      if( buf == 0 )
+      if( size <= 0  ) { size = BUFSIZ; }
+      if( buf == 0 ) {
          if (size == BUFSIZ) {
             int i;
             for(i=0;i<FIXED_BUFFERS;i++)
@@ -887,8 +888,10 @@ size_t size;
                }
             if(i==FIXED_BUFFERS)
                buf = malloc(size);
-         } else
+         } else {
             buf = malloc(size);
+	 }
+      }
       if( buf == 0 ) return EOF;
 
       fp->bufstart = buf;
@@ -896,6 +899,7 @@ size_t size;
       fp->mode |= mode;
    }
    fp->bufpos = fp->bufread = fp->bufwrite = fp->bufstart;
+   return 0;
 }
 #endif
 

+ 1 - 1
libc/stdlib/bsearch.c

@@ -28,7 +28,7 @@ register int (*cmp) ();		/* comparison function */
    while (a <= b)
    {
       c = (a + b) >> 1;		/* == ((a + b) / 2) */
-      if (dir = (*cmp) ((base + (c * size)), key))
+      if ((dir = (*cmp) ((base + (c * size)), key)))
       {
 	 if (dir > 0)
 	    b = c - 1;

+ 2 - 2
libc/stdlib/mkstemp.c

@@ -1,4 +1,4 @@
-
+#include <string.h>
 #include <features.h>
 #include <unistd.h>
 #include <fcntl.h>
@@ -7,7 +7,7 @@ int mkstemp(template)
 char * template;
 {
 	int i;
-	int num; /* UNINITIALIZED */
+	int num __attribute__ ((unused)); /* UNINITIALIZED */
 	int n2;
 	int l = strlen(template);
 	

+ 2 - 2
libc/stdlib/mktemp.c

@@ -1,4 +1,4 @@
-
+#include <string.h>
 #include <features.h>
 #include <unistd.h>
 #include <fcntl.h>
@@ -8,7 +8,7 @@ char * mktemp(template)
 char * template;
 {
 	int i;
-	int num; /* UNINITIALIZED */
+	int num __attribute__ ((unused)); /* UNINITIALIZED */
 	int n2;
 	int l = strlen(template);
 	struct stat stbuf;

+ 1 - 1
libc/stdlib/putenv.c

@@ -33,7 +33,7 @@ static int extras = 0;
    {
       if( memcmp(var, *p, len) == 0 && (*p)[len] == '=' )
       {
-         while( p[0] = p[1] ) p++;
+         while( (p[0] = p[1]) ) p++;
          extras++;
          break;
       }

+ 6 - 5
libc/stdlib/qsort.c

@@ -14,7 +14,7 @@ char *_qbuf = 0;		/* pointer to storage for qsort() */
 #define	PIVOT			((i+j)>>1)
 #define moveitem(dst,src,size)	if(dst != src) memcpy(dst, src, size)
 
-static 
+static void 
 _wqsort(base, lo, hi, cmp)
 register int *base;
 register int lo;
@@ -56,7 +56,7 @@ register int (*cmp) ();
    }
 }
 
-static 
+static void 
 _lqsort(base, lo, hi, cmp)
 register long *base;
 register int lo;
@@ -98,7 +98,7 @@ register int (*cmp) ();
    }
 }
 
-static 
+static void 
 _nqsort(base, lo, hi, size, cmp)
 register char *base;
 register int lo;
@@ -141,7 +141,7 @@ register int (*cmp) ();
    }
 }
 
-qsort(base, num, size, cmp)
+extern int qsort(base, num, size, cmp)
 char *base;
 int   num;
 int   size;
@@ -152,7 +152,7 @@ int   (*cmp) ();
    if (_qbuf == 0)
    {
       if (size > sizeof(_qtemp))/* records too large! */
-	 return;
+	 return 1;
       _qbuf = _qtemp;
    }
    if (size == 2)
@@ -163,4 +163,5 @@ int   (*cmp) ();
       _nqsort(base, 0, num - 1, size, cmp);
    if (_qbuf == _qtemp)
       _qbuf = 0;
+   return 0;
 }

+ 1 - 1
libc/stdlib/rand.c

@@ -41,7 +41,7 @@ static int seed3 = 1;
 
 int rand()
 {
-   register int q, z;
+   register int q;
    CRANK(206, 157,  31, 32363, seed1);
    CRANK(217, 146,  45, 31727, seed2);
    CRANK(222, 142, 133, 31657, seed3);

+ 2 - 1
libc/stdlib/setenv.c

@@ -35,7 +35,8 @@ static int extras = 0;
       {
          if (!overwrite)
          	return -1;
-         while( p[0] = p[1] ) p++;
+	 /* Overwrite stuff */
+         while( (p[0] = p[1]) ) p++;
          extras++;
          break;
       }

+ 1 - 1
libc/stdlib/system.c

@@ -7,7 +7,7 @@ int
 system(command)
 char * command;
 {
-   int wait_val, wait_ret, pid;
+   int wait_val, pid;
    __sighandler_t save_quit, save_int, save_chld;
 
    if( command == 0 ) return 1;

+ 1 - 1
libc/string/strsep.c

@@ -27,7 +27,7 @@ char *delim;
 
   if (!(p = *pp))
     return 0;
-  if (q = strpbrk (p, delim))
+  if ((q = strpbrk (p, delim)))
     {
       *pp = q + 1;
       *q = '\0';

+ 1 - 1
libc/string/strstr.c

@@ -17,7 +17,7 @@ char *s1; char *s2;
 
    if( l==0 ) return p;
 
-   while (p = strchr(p, *s2))
+   while ((p = strchr(p, *s2)))
    {
       if( memcmp(p, s2, l) == 0 )
          return p;

+ 1 - 1
libc/sysdeps/linux/Makefile

@@ -5,7 +5,7 @@ ARCH = $(shell uname -m | sed -e 's/i.86/i386/' | sed -e 's/sparc.*/sparc/')
 all: $(ARCH) common
 
 $(ARCH): dummy
-	echo Building for ARCH=$(ARCH)
+	@echo Building for ARCH=$(ARCH)
 	make -C $(ARCH)
 
 common:	dummy

+ 1 - 2
libc/sysdeps/linux/common/mkfifo.c

@@ -29,6 +29,5 @@
 int
 mkfifo (const char *path, mode_t mode)
 {
-  dev_t dev = 0;
-  return mknod (path, mode | S_IFIFO, &dev);
+  return mknod (path, mode | S_IFIFO, 0);
 }