version 1.21, 2015/10/03 20:12:53 |
version 1.22, 2015/10/05 06:54:59 |
|
|
* it possible to handle all "dodgy" directives correctly. |
* it possible to handle all "dodgy" directives correctly. |
*/ |
*/ |
|
|
#include "unifdef.h" |
#include <sys/stat.h> |
|
|
|
#include <ctype.h> |
|
#include <err.h> |
|
#include <stdarg.h> |
|
#include <stdbool.h> |
|
#include <stdio.h> |
|
#include <stdlib.h> |
|
#include <string.h> |
|
#include <unistd.h> |
|
|
static const char copyright[] = |
static const char copyright[] = |
#include "version.h" |
#include "version.h" |
"@(#) $Author$\n" |
"@(#) $Author$\n" |
|
|
static void usage(void); |
static void usage(void); |
static void version(void); |
static void version(void); |
static const char *xstrdup(const char *, const char *); |
static const char *xstrdup(const char *, const char *); |
|
static FILE * mktempmode(char *tmp, int mode); |
|
|
#define endsym(c) (!isalnum((unsigned char)c) && c != '_') |
#define endsym(c) (!isalnum((unsigned char)c) && c != '_') |
|
|
|
|
if (ifn == NULL || strcmp(ifn, "-") == 0) { |
if (ifn == NULL || strcmp(ifn, "-") == 0) { |
filename = "[stdin]"; |
filename = "[stdin]"; |
linefile = NULL; |
linefile = NULL; |
input = fbinmode(stdin); |
input = stdin; |
} else { |
} else { |
filename = ifn; |
filename = ifn; |
linefile = ifn; |
linefile = ifn; |
|
|
err(2, "can't open %s", ifn); |
err(2, "can't open %s", ifn); |
} |
} |
if (strcmp(ofn, "-") == 0) { |
if (strcmp(ofn, "-") == 0) { |
output = fbinmode(stdout); |
output = stdout; |
process(); |
process(); |
return; |
return; |
} |
} |
|
|
err(2, "can't rename \"%s\" to \"%s\"", ofn, backname); |
err(2, "can't rename \"%s\" to \"%s\"", ofn, backname); |
free(backname); |
free(backname); |
} |
} |
if (replace(tempname, ofn) < 0) |
if (rename(tempname, ofn) < 0) |
err(2, "can't rename \"%s\" to \"%s\"", tempname, ofn); |
err(2, "can't rename \"%s\" to \"%s\"", tempname, ofn); |
free(tempname); |
free(tempname); |
tempname = NULL; |
tempname = NULL; |
|
|
filename, linenum, msg, stifline[depth], depth); |
filename, linenum, msg, stifline[depth], depth); |
closeio(); |
closeio(); |
errx(2, "output may be truncated"); |
errx(2, "output may be truncated"); |
|
} |
|
|
|
static FILE * |
|
mktempmode(char *tmp, int mode) |
|
{ |
|
int fd = mkstemp(tmp); |
|
if (fd < 0) |
|
return (NULL); |
|
fchmod(fd, mode & (S_IRWXU|S_IRWXG|S_IRWXO)); |
|
return (fdopen(fd, "wb")); |
} |
} |