From: thib Date: Mon, 25 Feb 2002 18:46:14 +0000 (+0000) Subject: mv temp_file() and save*() to temp_file.c and save.c X-Git-Tag: ver1564~111 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ff1390e614764040f4ce473ee45336d375de0307;p=fcron mv temp_file() and save*() to temp_file.c and save.c --- diff --git a/subs.c b/subs.c index 630eacf..ead5756 100644 --- a/subs.c +++ b/subs.c @@ -22,14 +22,13 @@ * `LICENSE' that comes with the fcron source distribution. */ - /* $Id: subs.c,v 1.16 2001-12-23 22:05:20 thib Exp $ */ + /* $Id: subs.c,v 1.17 2002-02-25 18:46:14 thib Exp $ */ #include "global.h" #include "subs.h" void init_conf(void); -extern char *tmp_path; extern char debug_opt; /* fcron.conf parameters */ @@ -84,54 +83,6 @@ strdup2(const char *str) } -int -temp_file(char **name) - /* Open a temporary file and return its file descriptor */ -{ - int fd; -#ifdef HAVE_MKSTEMP - char name_local[PATH_LEN] = ""; - strcpy(name_local, tmp_path); - strcat(name_local, "fcr-XXXXXX"); - if ( (fd = mkstemp(name_local)) == -1 ) - die_e("Can't find a unique temporary filename"); - /* we must set the file mode to 600 (some version of mkstemp may set it - * incorrectly) */ - if ( fchmod(fd, S_IWUSR | S_IRUSR) != 0 ) - die_e("Can't fchmod temp file"); -#else - const int max_retries = 50; - char *name_local = NULL; - int i; - - i = 0; - do { - i++; - Set(name_local, tempnam(NULL, NULL)); - if ( name_local == NULL ) - die("Can't find a unique temporary filename"); - fd = open(name_local, O_RDWR|O_CREAT|O_EXCL|O_APPEND, S_IRUSR|S_IWUSR); - /* I'm not sure we actually need to be so persistent here */ - } while (fd == -1 && errno == EEXIST && i < max_retries); - if (fd == -1) - die_e("Can't open temporary file"); -#endif - if ( name == NULL && unlink(name_local) != 0 ) - die_e("Can't unlink temporary file %s", name_local); - - fcntl(fd, F_SETFD, 1); /* set close-on-exec flag */ - - /* give the name of the temp file if necessary */ - if (name != NULL) - *name = strdup2(name_local); -#ifndef HAVE_MKSTEMP - free(name_local); -#endif - - return fd; -} - - void init_conf(void) /* initialises config with compiled in constants */ @@ -251,71 +202,3 @@ read_conf(void) fclose(f); } - - -int -save_type(FILE *f, short int type) -/* save a single type (with no data attached) in a binary fcrontab file */ -{ - short int size = 0; - - if ( write(fileno(f), &type, sizeof(type)) < sizeof(type) ) goto err; - if ( write(fileno(f), &size, sizeof(size)) < sizeof(size) ) goto err; - - return OK; - - err: - return ERR; - -} - -int -save_str(FILE *f, short int type, char *str) -/* save a string of type "type" in a binary fcrontab file */ -{ - short int size = 0; - size = strlen(str); - - if ( write(fileno(f), &type, sizeof(type)) < sizeof(type) ) goto err; - if ( write(fileno(f), &size, sizeof(size)) < sizeof(size) ) goto err; - if ( write(fileno(f), str, size) < size ) goto err; - - return OK; - - err: - return ERR; - -} - -int -save_strn(FILE *f, short int type, char *str, short int size) -/* save a "size"-length string of type "type" in a binary fcrontab file */ -{ - - if ( write(fileno(f), &type, sizeof(type)) < sizeof(type) ) goto err; - if ( write(fileno(f), &size, sizeof(size)) < sizeof(size) ) goto err; - if ( write(fileno(f), str, size) < size ) goto err; - - return OK; - - err: - return ERR; - -} - -int -save_lint(FILE *f, short int type, long int value) -/* save an integer of type "type" in a binary fcrontab file */ -{ - short int size = sizeof(value); - - if ( write(fileno(f), &type, sizeof(type)) < sizeof(type) ) goto err; - if ( write(fileno(f), &size, sizeof(size)) < sizeof(size) ) goto err; - if ( write(fileno(f), &value, size) < size ) goto err; - - return OK; - - err: - return ERR; - -} diff --git a/subs.h b/subs.h index 77b8fda..474b9b9 100644 --- a/subs.h +++ b/subs.h @@ -21,7 +21,7 @@ * `LICENSE' that comes with the fcron source distribution. */ - /* $Id: subs.h,v 1.4 2001-12-23 22:05:24 thib Exp $ */ + /* $Id: subs.h,v 1.5 2002-02-25 18:46:31 thib Exp $ */ #ifndef __SUBS_H__ #define __SUBS_H__ @@ -45,9 +45,5 @@ extern int remove_blanks(char *str); extern char *strdup2(const char *); extern int temp_file(char **name); extern void read_conf(void); -extern int save_type(FILE *f, short int type); -extern int save_str(FILE *f, short int type, char *str); -extern int save_strn(FILE *f, short int type, char *str, short int size); -extern int save_lint(FILE *f, short int type, long int value); #endif /* __SUBS_H__ */