version 1.5, 1998/05/29 21:07:22 |
version 1.6, 1998/08/31 02:13:41 |
|
|
#endif /* not lint */ |
#endif /* not lint */ |
|
|
/* |
/* |
* uudecode [file ...] |
* uudecode [-p] [file ...] |
* |
* |
* create the specified file, decoding as you go. |
* create the specified file, decoding as you go. |
* used with uuencode. |
* used with uuencode. |
|
* |
|
* Write to stdout if '-p' is specified. Use this option if you care about |
|
* security at all. |
*/ |
*/ |
#include <stdio.h> |
#include <stdio.h> |
#include <string.h> |
#include <string.h> |
|
|
#include <pwd.h> |
#include <pwd.h> |
#include <unistd.h> |
#include <unistd.h> |
|
|
static int decode(); |
static int decode(int); |
static void usage(); |
static void usage(); |
char *filename; |
char *filename; |
|
|
|
|
char *argv[]; |
char *argv[]; |
{ |
{ |
int rval; |
int rval; |
|
char ch; |
|
int tostdout = 0; |
|
|
setlocale(LC_ALL, ""); |
setlocale(LC_ALL, ""); |
|
|
while (getopt(argc, argv, "") != -1) |
while ((ch = getopt(argc, argv, "p")) != -1) |
usage(); |
switch((char)ch) { |
|
case 'p': |
|
tostdout++; |
|
break; |
|
case '?': |
|
default: |
|
usage(); |
|
} |
argc -= optind; |
argc -= optind; |
argv += optind; |
argv += optind; |
|
|
|
|
rval = 1; |
rval = 1; |
continue; |
continue; |
} |
} |
rval |= decode(); |
rval |= decode(tostdout); |
} while (*++argv); |
} while (*++argv); |
} else { |
} else { |
filename = "stdin"; |
filename = "stdin"; |
rval = decode(); |
rval = decode(tostdout); |
} |
} |
exit(rval); |
exit(rval); |
} |
} |
|
|
static int |
static int |
decode() |
decode(int tostdout) |
{ |
{ |
extern int errno; |
extern int errno; |
struct passwd *pw; |
struct passwd *pw; |
|
|
buf[n] = '/'; |
buf[n] = '/'; |
} |
} |
|
|
/* create output file, set mode */ |
if (!tostdout) { |
if (!freopen(buf, "w", stdout) || |
/* create output file, set mode */ |
fchmod(fileno(stdout), mode&0666)) { |
if (!freopen(buf, "w", stdout) || |
(void)fprintf(stderr, "uudecode: %s: %s: %s\n", buf, |
fchmod(fileno(stdout), mode&0666)) { |
filename, strerror(errno)); |
(void)fprintf(stderr, "uudecode: %s: %s: %s\n", buf, |
return(1); |
filename, strerror(errno)); |
|
return(1); |
|
} |
} |
} |
|
|
/* for each input line */ |
/* for each input line */ |
|
|
static void |
static void |
usage() |
usage() |
{ |
{ |
(void)fprintf(stderr, "usage: uudecode [file ...]\n"); |
(void)fprintf(stderr, "usage: uudecode [-p] [file ...]\n"); |
exit(1); |
exit(1); |
} |
} |