diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/build.c | 48 | ||||
| -rw-r--r-- | src/filepath.c | 10 | ||||
| -rw-r--r-- | src/redo.c | 6 | ||||
| -rw-r--r-- | src/util.c | 6 | ||||
| -rw-r--r-- | src/util.h | 2 | 
5 files changed, 36 insertions, 36 deletions
diff --git a/src/build.c b/src/build.c index 5ddda64..18ead3f 100644 --- a/src/build.c +++ b/src/build.c @@ -70,7 +70,7 @@ int build_target(const char *target) {  	char *dep_file = get_dep_path(target);  	if (remove(dep_file))  		if (errno != ENOENT) -			diem("redo: failed to remove %s", dep_file); +			fatal("redo: failed to remove %s", dep_file);  	free(dep_file);  	char *temp_output = concat(2, target, ".redoing.tmp"); @@ -78,7 +78,7 @@ int build_target(const char *target) {  	pid_t pid = fork();  	if (pid == -1) {  		/* failure */ -		diem("redo: failed to fork() new process"); +		fatal("redo: failed to fork() new process");  	} else if (pid == 0) {  		/* child */ @@ -86,7 +86,7 @@ int build_target(const char *target) {  		char *dirc = xstrdup(target);  		char *dtarget = dirname(dirc);  		if (chdir(dtarget) == -1) -			diem("redo: failed to change directory to %s", dtarget); +			fatal("redo: failed to change directory to %s", dtarget);  		free(dirc); @@ -99,7 +99,7 @@ int build_target(const char *target) {  		/* set "REDO_PARENT_TARGET" */  		if (setenv("REDO_PARENT_TARGET", target, 1)) -			diem("redo: failed to setenv() REDO_PARENT_TARGET to %s", target); +			fatal("redo: failed to setenv() REDO_PARENT_TARGET to %s", target);  		/* excelp() has nearly everything we want: automatic parsing of the  		   shebang line through execve() and fallback to /bin/sh if no valid @@ -109,13 +109,13 @@ int build_target(const char *target) {  		execv(argv[0], argv);  		/* execv should never return */ -		diem("redo: failed to replace child process with %s", argv[0]); +		fatal("redo: failed to replace child process with %s", argv[0]);  	}  	/* parent */  	int status;  	if (waitpid(pid, &status, 0) == -1) -		diem("waitpid() failed: "); +		fatal("waitpid() failed: ");  	bool remove_temp = true;  	if (WIFEXITED(status)) { @@ -149,10 +149,10 @@ int build_target(const char *target) {  	if (remove_temp) {  		if (remove(temp_output))  			if (errno != ENOENT) -				diem("redo: failed to remove %s", temp_output); +				fatal("redo: failed to remove %s", temp_output);  	} else {  		if (rename(temp_output, target)) -			diem("redo: failed to rename %s to %s", temp_output, target); +			fatal("redo: failed to rename %s to %s", temp_output, target);  		write_dep_hash(target);  	} @@ -168,13 +168,13 @@ int build_target(const char *target) {  static char **parse_shebang(char *target, char *dofile, char *temp_output) {  	FILE *fp = fopen(dofile, "rb");  	if (!fp) -		diem("redo: failed to open %s", dofile); +		fatal("redo: failed to open %s", dofile);  	char buf[1024];  	buf[ fread(buf, 1, sizeof(buf)-1, fp) ] = '\0';  	if (ferror(fp)) -		diem("redo: failed to read from %s", dofile); +		fatal("redo: failed to read from %s", dofile);  	fclose(fp); @@ -286,7 +286,7 @@ static char *get_relpath(const char *target) {  	char *abstarget = xrealpath(target);  	if (!abstarget) -		diem("redo: failed to get realpath() of %s", target); +		fatal("redo: failed to get realpath() of %s", target);  	char *relpath = xstrdup(make_relative(root, abstarget));  	free(abstarget); @@ -318,11 +318,11 @@ void add_dep(const char *target, const char *parent, int ident) {  		if (errno == ENOENT) {  			fp = fopen(dep_path, "w");  			if (!fp) -				diem("redo: failed to open %s", dep_path); +				fatal("redo: failed to open %s", dep_path);  			/* skip the first n bytes that are reserved for the header */  			fseek(fp, HEADERSIZE, SEEK_SET);  		} else { -			diem("redo: failed to open %s", dep_path); +			fatal("redo: failed to open %s", dep_path);  		}  	} else {  		fseek(fp, 0L, SEEK_END); @@ -335,10 +335,10 @@ void add_dep(const char *target, const char *parent, int ident) {  	putc('\0', fp);  	if (ferror(fp)) -		diem("redo: failed to write to %s", dep_path); +		fatal("redo: failed to write to %s", dep_path);  	if (fclose(fp)) -		diem("redo: failed to close %s", dep_path); +		fatal("redo: failed to close %s", dep_path);  	free(dep_path);  	free(reltarget);  } @@ -347,7 +347,7 @@ void add_dep(const char *target, const char *parent, int ident) {  static void hash_file(const char *target, unsigned char *hash) {  	FILE *in = fopen(target, "rb");  	if (!in) -		diem("redo: failed to open %s", target); +		fatal("redo: failed to open %s", target);  	SHA_CTX context;  	unsigned char data[8192]; @@ -358,7 +358,7 @@ static void hash_file(const char *target, unsigned char *hash) {  		SHA1_Update(&context, data, read);  	if (ferror(in)) -		diem("redo: failed to read from %s", target); +		fatal("redo: failed to read from %s", target);  	SHA1_Final(hash, &context);  	fclose(in);  } @@ -373,16 +373,16 @@ static void write_dep_hash(const char *target) {  	char *dep_path = get_dep_path(target);  	int out = open(dep_path, O_WRONLY | O_CREAT, 0644);  	if (out < 0) -		diem("redo: failed to open %s", dep_path); +		fatal("redo: failed to open %s", dep_path);  	if (write(out, &magic, sizeof(unsigned)) < (ssize_t) sizeof(unsigned)) -		diem("redo: failed to write magic number to '%s'", dep_path); +		fatal("redo: failed to write magic number to '%s'", dep_path);  	if (write(out, hash, sizeof hash) < (ssize_t) sizeof hash) -		diem("redo: failed to write hash to '%s'", dep_path); +		fatal("redo: failed to write hash to '%s'", dep_path);  	if (close(out)) -		diem("redo: failed to close %s", dep_path); +		fatal("redo: failed to close %s", dep_path);  	free(dep_path);  } @@ -427,14 +427,14 @@ static int handle_c(const char *target) {  			free(dep_path);  			return 1;  		} else { -			diem("redo: failed to open %s", dep_path); +			fatal("redo: failed to open %s", dep_path);  		}  	}  	char buf[8096 > FILENAME_MAX+3 ? 8096 : FILENAME_MAX*2];  	if (fread(buf, 1, HEADERSIZE, fp) < HEADERSIZE) -		diem("redo: failed to read %zu bytes from %s", HEADERSIZE, dep_path); +		fatal("redo: failed to read %zu bytes from %s", HEADERSIZE, dep_path);  	free(dep_path); @@ -459,7 +459,7 @@ static int handle_c(const char *target) {  		size_t read = fread(buf, 1, sizeof buf, fp);  		if (ferror(fp)) -			diem("redo: failed to read %zu bytes from descriptor", sizeof buf); +			fatal("redo: failed to read %zu bytes from descriptor", sizeof buf);  		for (size_t i = 0; i < read; ++i) {  			if (buf[i]) diff --git a/src/filepath.c b/src/filepath.c index 6aca4a7..d0b68de 100644 --- a/src/filepath.c +++ b/src/filepath.c @@ -121,7 +121,7 @@ off_t fsize(const char *fn) {  	struct stat st;  	if (stat(fn, &st)) {  		if (errno != ENOENT) -			diem("redo: failed to aquire stat() information about %s", fn); +			fatal("redo: failed to aquire stat() information about %s", fn);  		return -1;  	} @@ -136,16 +136,16 @@ bool mkdirp(const char *dir) {  	if (stat(dir, &st)) {  		/* dir doesn't exist or stat failed */  		if (errno != ENOENT) -			diem("redo: failed to aquire stat() information about %s", dir); +			fatal("redo: failed to aquire stat() information about %s", dir);  		if (mkdir(dir, 0755)) -			diem("redo: failed to mkdir() '%s'", dir); +			fatal("redo: failed to mkdir() '%s'", dir);  		return 1;  	} else {  		if (!S_ISDIR(st.st_mode)) {  			if (remove(dir)) -				diem("redo: failed to remove %s", dir); +				fatal("redo: failed to remove %s", dir);  			if (mkdir(dir, 0755)) -				diem("redo: failed to mkdir() '%s'", dir); +				fatal("redo: failed to mkdir() '%s'", dir);  			return 1;  		}  		return 0; @@ -38,9 +38,9 @@ void prepare_env() {  	/* set REDO_ROOT */  	char *cwd = getcwd(NULL, 0);  	if (!cwd) -		diem("redo: failed to obtain cwd"); +		fatal("redo: failed to obtain cwd");  	if (setenv("REDO_ROOT", cwd, 0)) -		diem("redo: failed to setenv() REDO_ROOT to %s", cwd); +		fatal("redo: failed to setenv() REDO_ROOT to %s", cwd);  	free(cwd);  	/* set REDO_MAGIC */ @@ -48,7 +48,7 @@ void prepare_env() {  	char magic_str[digits(UINT_MAX) + 1];  	sprintf(magic_str, "%u", rand());  	if (setenv("REDO_MAGIC", magic_str, 0)) -		diem("redo: failed to setenv() REDO_MAGIC to %s", magic_str); +		fatal("redo: failed to setenv() REDO_MAGIC to %s", magic_str);  }  int main(int argc, char *argv[]) { @@ -36,7 +36,7 @@ void *xmalloc(size_t size) {  	assert(size > 0);  	void *ptr = malloc(size);  	if (!ptr) -		diem("Cannot allocate %zu bytes", size); +		fatal("Cannot allocate %zu bytes", size);  	return ptr;  } @@ -44,7 +44,7 @@ void *xmalloc(size_t size) {  void *xrealloc(void *ptr, size_t size) {  	assert(size > 0 && ptr);  	if (!(ptr = realloc(ptr, size))) -		diem("Cannot reallocate %zu bytes", size); +		fatal("Cannot reallocate %zu bytes", size);  	return ptr;  } @@ -52,7 +52,7 @@ void *xrealloc(void *ptr, size_t size) {  char *xstrdup(const char *str) {  	assert(str);  	if (!(str = strdup(str))) -		diem("Insufficient memory for string allocation"); +		fatal("Insufficient memory for string allocation");  	return (char*) str;  } @@ -12,7 +12,7 @@  #include <stddef.h>  #define DIE_HELPER(M, ...) die(M ": %s\n", __VA_ARGS__) -#define diem(...) DIE_HELPER(__VA_ARGS__, strerror(errno)) +#define fatal(...) DIE_HELPER(__VA_ARGS__, strerror(errno))  extern void __attribute__((noreturn)) die(const char *err, ...);  extern void *xmalloc(size_t size);  | 
