1 /* lp 1.4 - Send file to the lineprinter Author: Kees J. Bot
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
)
30 /* Start the lpd daemon giving it the file to spool and print. */
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
);
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];
51 int main(int argc
, char **argp
)
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
) {
69 if (open(file
, O_RDONLY
) != 0) {
78 if (cwdsize
+ 1 + strlen(file
) + 1 > sizeof(path
)) {
80 "lp: full pathname of %s is too long\n",
86 strcpy(path
+ cwdsize
+ 1, file
);