Remove building with NOCRYPTO option
[minix.git] / minix / commands / lp / lp.c
blob8ea373aab01b8e6faf2aeddcab41b32e5fc161cc
1 /* lp 1.4 - Send file to the lineprinter Author: Kees J. Bot
2 * 3 Dec 1989
3 */
4 #define nil 0
5 #include <sys/types.h>
6 #include <stdio.h>
7 #include <limits.h>
8 #include <stdlib.h>
9 #include <unistd.h>
10 #include <fcntl.h>
11 #include <string.h>
12 #include <errno.h>
13 #include <sys/wait.h>
15 char LPD1[] = "/usr/sbin/lpd"; /* Proper place of lpd */
16 char LPD2[] = "/usr/bin/lpd"; /* Minix has no sbin directories. */
18 void report(char *mess)
20 fprintf(stderr, "lp: %s: %s\n", mess, strerror(errno));
23 void fatal(char *mess)
25 report(mess);
26 exit(1);
29 void lp(char *file)
30 /* Start the lpd daemon giving it the file to spool and print. */
32 int pid, status;
34 if (file[0] != '/' || (pid= fork()) == 0) {
35 execl(LPD1, LPD1, file, (char *) nil);
36 if (errno != ENOENT) fatal(LPD1);
37 execl(LPD2, LPD2, file, (char *) nil);
38 fatal(LPD2);
41 if (pid < 0) fatal("can't fork");
43 if (waitpid(pid, &status, 0) < 0) fatal("wait");
45 if (status != 0) exit(1);
48 char path[PATH_MAX+1];
49 int cwdsize;
51 int main(int argc, char **argp)
53 int e=0;
54 char *file;
56 if (argc <= 1) lp("stdin");
58 /* Lpd requires full path names, so find out where we are. */
59 if (getcwd(path, sizeof(path)) == nil)
60 fatal("Can't determine current directory");
62 cwdsize= strlen(path);
64 /* Hand each file to lpd. */
65 while ((file= *++argp) != nil) {
67 close(0);
69 if (open(file, O_RDONLY) != 0) {
70 report(file);
71 e=1;
72 continue;
74 if (file[0] == '/') {
75 lp(file);
76 continue;
78 if (cwdsize + 1 + strlen(file) + 1 > sizeof(path)) {
79 fprintf(stderr,
80 "lp: full pathname of %s is too long\n",
81 file);
82 e=1;
83 continue;
85 path[cwdsize] = '/';
86 strcpy(path + cwdsize + 1, file);
88 lp(path);
90 exit(e);