Better portability to other systems.
authorThomas Ferrin <tef@ucbvax.Berkeley.EDU>
Sat, 29 Apr 1995 06:39:34 +0000 (22:39 -0800)
committerThomas Ferrin <tef@ucbvax.Berkeley.EDU>
Sat, 29 Apr 1995 06:39:34 +0000 (22:39 -0800)
SCCS-vsn: usr.sbin/lpr/common_source/common.c 8.5
SCCS-vsn: usr.sbin/lpr/common_source/printcap.c 8.2
SCCS-vsn: usr.sbin/lpr/common_source/displayq.c 8.4
SCCS-vsn: usr.sbin/lpr/lpd/printjob.c 8.6
SCCS-vsn: usr.sbin/lpr/lpd/lpd.c 8.6

usr/src/usr.sbin/lpr/common_source/common.c
usr/src/usr.sbin/lpr/common_source/displayq.c
usr/src/usr.sbin/lpr/common_source/printcap.c
usr/src/usr.sbin/lpr/lpd/lpd.c
usr/src/usr.sbin/lpr/lpd/printjob.c

index f78d2bc..fef5817 100644 (file)
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)common.c   8.4 (Berkeley) %G%";
+static char sccsid[] = "@(#)common.c   8.5 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/param.h>
 #include <sys/stat.h>
 #endif /* not lint */
 
 #include <sys/param.h>
 #include <sys/stat.h>
+#include <sys/time.h>
 
 #include <sys/socket.h>
 #include <netinet/in.h>
 
 #include <sys/socket.h>
 #include <netinet/in.h>
index d94a62b..07a15e1 100644 (file)
@@ -6,11 +6,12 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)displayq.c 8.3 (Berkeley) %G%";
+static char sccsid[] = "@(#)displayq.c 8.4 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/param.h>
 #include <sys/stat.h>
 #endif /* not lint */
 
 #include <sys/param.h>
 #include <sys/stat.h>
+#include <sys/file.h>
 
 #include <signal.h>
 #include <fcntl.h>
 
 #include <signal.h>
 #include <fcntl.h>
index 669a047..151c915 100644 (file)
@@ -6,7 +6,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)printcap.c 8.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)printcap.c 8.2 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/param.h>
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -25,6 +25,87 @@ static char sccsid[] = "@(#)printcap.c       8.1 (Berkeley) %G%";
 #endif
 #define MAXHOP 32      /* max number of tc= indirections */
 
 #endif
 #define MAXHOP 32      /* max number of tc= indirections */
 
+/*
+ * getcap-style interface for the old printcap routines.
+ *
+ * !!!USE THIS INTERFACE ONLY IF YOU DON'T HAVE THE REAL GETCAP!!!
+ */
+
+static char *pbp;              /* pointer into pbuf for pgetstr() */
+static char pbuf[BUFSIZ];      /* buffer for capability strings */
+extern char line[];            /* buffer for printcap entries */
+
+int
+cgetnext(bp, db_array)
+        register char **bp;
+       char **db_array;
+{
+       int ret;
+       char *strdup();
+
+       pbp = pbuf;
+       ret = getprent(line);
+       *bp = strdup(line);
+       return (ret);
+}
+
+int
+cgetent(bp, db_array, name)
+       char **bp, **db_array, *name;
+{
+       int i;
+
+       *bp = line;
+       pbp = pbuf;
+       i = pgetent(*bp, name);
+       if (i < 0)
+               return (-2);
+       else if (i == 0)
+               return (-1);
+       else
+               return (0);
+}
+
+char *
+cgetcap(buf, cap, type)
+       char *buf, *cap;
+       int type;
+{
+       return ((char *) pgetflag(cap));
+}
+
+int
+cgetstr(buf, cap, str)
+       char *buf, *cap;
+       char **str;
+{
+       char *pgetstr __P((char *, char **));
+
+       if (pbp >= pbuf+BUFSIZ) {
+               write(2, "Capability string buffer overflow\n", 34);
+               return (-1);
+       }
+       return ((*str = pgetstr(cap, &pbp)) == NULL ? -1 : 0);
+}
+
+int
+cgetnum(buf, cap, num)
+       char *buf, *cap;
+       long *num;
+{
+       return ((*num = pgetnum(cap)) < 0 ? -1 : 0);
+}
+
+int
+cgetclose()
+{
+       void endprent __P((void));
+
+       endprent();
+       return (0);
+}
+
+
 /*
  * termcap - routines for dealing with the terminal capability data base
  *
 /*
  * termcap - routines for dealing with the terminal capability data base
  *
@@ -57,9 +138,10 @@ static char sccsid[] = "@(#)printcap.c      8.1 (Berkeley) %G%";
 static FILE *pfp = NULL;       /* printcap data base file pointer */
 static char *tbuf;
 static int hopcount;           /* detect infinite loops in termcap, init 0 */
 static FILE *pfp = NULL;       /* printcap data base file pointer */
 static char *tbuf;
 static int hopcount;           /* detect infinite loops in termcap, init 0 */
+static int tf;
 
 
+char *tgetstr __P((char *, char **));
 static char *tskip __P((char *));
 static char *tskip __P((char *));
-static char *tskip __P((char *bp));
 static char *tdecode __P((char *, char **));
 
 /*
 static char *tdecode __P((char *, char **));
 
 /*
@@ -111,8 +193,18 @@ getprent(bp)
 void
 endprent()
 {
 void
 endprent()
 {
-       if (pfp != NULL)
-               fclose(pfp);
+       if (pfp != NULL) {
+               /*
+                * Can't use fclose here because on POSIX-compliant
+                * systems, fclose() causes the file pointer of the
+                * underlying file descriptor (which is possibly shared
+                * with a parent process) to be adjusted, and this
+                * reeks havoc in the parent because it doesn't know
+                * the file pointer has changed.
+                */
+               (void) close(fileno(pfp));
+               pfp = NULL;
+       }
 }
 
 /*
 }
 
 /*
@@ -128,10 +220,8 @@ tgetent(bp, name)
        register int c;
        register int i = 0, cnt = 0;
        char ibuf[BUFSIZ];
        register int c;
        register int i = 0, cnt = 0;
        char ibuf[BUFSIZ];
-       int tf;
 
        tbuf = bp;
 
        tbuf = bp;
-       tf = 0;
 #ifndef V6
        cp = getenv("TERMCAP");
        /*
 #ifndef V6
        cp = getenv("TERMCAP");
        /*
@@ -153,11 +243,9 @@ tgetent(bp, name)
                } else
                        tf = open(cp, 0);
        }
                } else
                        tf = open(cp, 0);
        }
+#endif
        if (tf==0)
                tf = open(_PATH_PRINTCAP, 0);
        if (tf==0)
                tf = open(_PATH_PRINTCAP, 0);
-#else
-       tf = open(_PATH_PRINTCAP, 0);
-#endif
        if (tf < 0)
                return (-1);
        for (;;) {
        if (tf < 0)
                return (-1);
        for (;;) {
@@ -167,6 +255,7 @@ tgetent(bp, name)
                                cnt = read(tf, ibuf, BUFSIZ);
                                if (cnt <= 0) {
                                        close(tf);
                                cnt = read(tf, ibuf, BUFSIZ);
                                if (cnt <= 0) {
                                        close(tf);
+                                       tf = 0;
                                        return (0);
                                }
                                i = 0;
                                        return (0);
                                }
                                i = 0;
@@ -191,8 +280,13 @@ tgetent(bp, name)
                 * The real work for the match.
                 */
                if (tnamatch(name)) {
                 * The real work for the match.
                 */
                if (tnamatch(name)) {
-                       close(tf);
-                       return(tnchktc());
+                       lseek(tf, 0L, 0);
+                       i = tnchktc();
+                       if (tf) {
+                               close(tf);
+                               tf = 0;
+                       }
+                       return(i);
                }
        }
 }
                }
        }
 }
@@ -429,4 +523,3 @@ nextc:
        *area = cp;
        return (str);
 }
        *area = cp;
        return (str);
 }
-
index 6008964..ea0ffc0 100644 (file)
@@ -13,7 +13,7 @@ static char copyright[] =
 #endif /* not lint */
 
 #ifndef lint
 #endif /* not lint */
 
 #ifndef lint
-static char sccsid[] = "@(#)lpd.c      8.5 (Berkeley) %G%";
+static char sccsid[] = "@(#)lpd.c      8.6 (Berkeley) %G%";
 #endif /* not lint */
 
 /*
 #endif /* not lint */
 
 /*
@@ -51,6 +51,7 @@ static char sccsid[] = "@(#)lpd.c     8.5 (Berkeley) %G%";
 #include <sys/socket.h>
 #include <sys/un.h>
 #include <sys/stat.h>
 #include <sys/socket.h>
 #include <sys/un.h>
 #include <sys/stat.h>
+#include <sys/file.h>
 #include <netinet/in.h>
 
 #include <netdb.h>
 #include <netinet/in.h>
 
 #include <netdb.h>
@@ -403,7 +404,7 @@ startup()
         * Restart the daemons.
         */
        while (cgetnext(&buf, printcapdb) > 0) {
         * Restart the daemons.
         */
        while (cgetnext(&buf, printcapdb) > 0) {
-               if (ckqueue() <= 0 ) {
+               if (ckqueue() <= 0) {
                        free(buf);
                        continue;       /* no work to do for this printer */
                }
                        free(buf);
                        continue;       /* no work to do for this printer */
                }
index 4de473f..ea52308 100644 (file)
@@ -13,7 +13,7 @@ static char copyright[] =
 #endif /* not lint */
 
 #ifndef lint
 #endif /* not lint */
 
 #ifndef lint
-static char sccsid[] = "@(#)printjob.c 8.5 (Berkeley) %G%";
+static char sccsid[] = "@(#)printjob.c 8.6 (Berkeley) %G%";
 #endif /* not lint */
 
 
 #endif /* not lint */
 
 
@@ -28,6 +28,7 @@ static char sccsid[] = "@(#)printjob.c        8.5 (Berkeley) %G%";
 #include <sys/wait.h>
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <sys/wait.h>
 #include <sys/stat.h>
 #include <sys/types.h>
+#include <sys/file.h>
 
 #include <pwd.h>
 #include <unistd.h>
 
 #include <pwd.h>
 #include <unistd.h>
@@ -222,7 +223,7 @@ again:
                        if (ofilter > 0) {
                                kill(ofilter, SIGCONT); /* to be sure */
                                (void) close(ofd);
                        if (ofilter > 0) {
                                kill(ofilter, SIGCONT); /* to be sure */
                                (void) close(ofd);
-                               while ((i = wait(0)) > 0 && i != ofilter)
+                               while ((i = wait(NULL)) > 0 && i != ofilter)
                                        ;
                                ofilter = 0;
                        }
                                        ;
                                ofilter = 0;
                        }
@@ -1063,7 +1064,7 @@ sendmail(user, bombed)
        }
        (void) close(p[0]);
        (void) close(p[1]);
        }
        (void) close(p[0]);
        (void) close(p[1]);
-       wait(&s);
+       wait(NULL);
        syslog(LOG_INFO, "mail sent to user %s about job %s on printer %s (%s)",
                user, *jobname ? jobname : "<unknown>", printer, cp);
 }
        syslog(LOG_INFO, "mail sent to user %s about job %s on printer %s (%s)",
                user, *jobname ? jobname : "<unknown>", printer, cp);
 }
@@ -1431,7 +1432,7 @@ setty()
 #include <varargs.h>
 #endif
 
 #include <varargs.h>
 #endif
 
-void
+static void
 #if __STDC__
 pstatus(const char *msg, ...)
 #else
 #if __STDC__
 pstatus(const char *msg, ...)
 #else