* `LICENSE' that comes with the fcron source distribution.
*/
- /* $Id: conf.c,v 1.57 2002-08-30 20:05:51 thib Exp $ */
+ /* $Id: conf.c,v 1.58 2002-09-07 13:11:45 thib Exp $ */
#include "fcron.h"
struct stat file_stat;
struct passwd *pass = NULL;
short int type = 0, size = 0;
+ int rc;
/* open file */
if ( (ff = fopen(file_name, "r")) == NULL ) {
/* check if this file is owned by root : otherwise, all runas fields
* of this field should be set to the owner */
- if ( fstat(fileno(ff), &file_stat) != 0 ) {
+ rc = fstat(fileno(ff), &file_stat);
+ if ( rc != 0 ) {
error_e("Could not stat %s", file_name);
goto err;
}
if ( strncmp(file_name,"new.", 4) == 0 ) {
- if ( file_stat.st_uid == ROOTUID )
+ if ( file_stat.st_uid == ROOTUID ) {
/* file is owned by root : no test needed : set runas to ROOTUID */
runas = ROOTUID;
+ }
else {
/* this is a standard user's new fcrontab : set the runas field to
* the owner of the file */
}
}
else {
- if ( file_stat.st_uid == ROOTUID )
+ if ( file_stat.st_uid == ROOTUID ) {
/* file is owned by root : either this file has already been parsed
* at least once by fcron, or it is root's fcrontab */
runas = ROOTUID;
+ }
else {
error("Non-new file %s owned by someone else than root",file_name);
goto err;
/* save_file() error management */
-#define Save_type(f, type) \
+#define Save_type(fd, type) \
{ \
- if ( save_type(f, type) != OK ) { \
+ if ( save_type(fd, type) != OK ) { \
error_e("Could not write type : file has not been saved."); \
- fclose(f); \
+ close(fd); \
remove(file->cf_user); \
goto next_file; \
} \
}
-#define Save_str(f, type, str) \
+#define Save_str(fd, type, str) \
{ \
- if ( save_str(f, type, str) != OK ) { \
+ if ( save_str(fd, type, str) != OK ) { \
error_e("Could not write str : file has not been saved."); \
- fclose(f); \
+ close(fd); \
remove(file->cf_user); \
goto next_file; \
} \
}
-#define Save_strn(f, type, str, size) \
+#define Save_strn(fd, type, str, size) \
{ \
- if ( save_strn(f, type, str, size) != OK ) { \
+ if ( save_strn(fd, type, str, size) != OK ) { \
error_e("Could not write strn : file has not been saved."); \
- fclose(f); \
+ close(fd); \
remove(file->cf_user); \
goto next_file; \
} \
}
-#define Save_lint(f, type, value) \
+#define Save_lint(fd, type, value) \
{ \
- if ( save_lint(f, type, value) != OK ) { \
+ if ( save_lint(fd, type, value) != OK ) { \
error_e("Could not write lint : file has not been saved."); \
- fclose(f); \
+ close(fd); \
remove(file->cf_user); \
goto next_file; \
} \
{
CF *file = NULL;
CL *line = NULL;
- FILE *f = NULL;
+ int fd;
CF *start_file = NULL;
env_t *env = NULL;
debug("Saving %s...", file->cf_user);
/* open file */
- if ( (f = fopen(file->cf_user, "w")) == NULL ) {
+ fd = open(file->cf_user, O_CREAT | O_TRUNC | O_SYNC);
+ if ( fd == -1 ) {
error_e("Could not open %s", file->cf_user);
goto next_file;
}
/* chown the file to root:root : this file should only be read and
* modified by fcron (not fcrontab) */
- if (fchown(fileno(f), ROOTUID, ROOTGID) != 0)
+ if (fchown(fd, ROOTUID, ROOTGID) != 0)
error_e("Could not fchown \"%s\"", file->cf_user);
/* save file : */
* a file using a depreciated format generated by an old fcrontab,
* if the syntax has changed */
/* an binary fcrontab *must* start by such a header */
- Save_lint(f, S_HEADER_T, S_FILEVERSION );
+ Save_lint(fd, S_HEADER_T, S_FILEVERSION );
/* put the user's name : needed to check if his uid has not changed */
/* S_USER_T *must* be the 2nd field of a binary fcrontab */
- Save_str(f, S_USER_T, file->cf_user);
+ Save_str(fd, S_USER_T, file->cf_user);
/* put the time & date of saving : this is use for calcutating
* the system down time. As it is a new file, we set it to 0 */
/* S_USER_T *must* be the 3rd field of a binary fcrontab */
- Save_lint(f, S_TIMEDATE_T, now);
+ Save_lint(fd, S_TIMEDATE_T, now);
/* Save the time diff between local (real) and system hour (if any) */
if ( file->cf_tzdiff != 0 )
- Save_lint(f, S_TZDIFF_T, file->cf_tzdiff);
+ Save_lint(fd, S_TZDIFF_T, file->cf_tzdiff);
/* env variables, */
for (env = file->cf_env_base; env; env = env->e_next)
- Save_str(f, S_ENVVAR_T, env->e_val);
+ Save_str(fd, S_ENVVAR_T, env->e_val);
/* then, lines. */
for (line = file->cf_line_base; line; line = line->cl_next) {
/* this ones are saved for every lines */
- Save_str(f, S_SHELL_T, line->cl_shell);
- Save_str(f, S_RUNAS_T, line->cl_runas);
- Save_str(f, S_MAILTO_T, line->cl_mailto);
- Save_strn(f, S_OPTION_T, line->cl_option, OPTION_SIZE);
+ Save_str(fd, S_SHELL_T, line->cl_shell);
+ Save_str(fd, S_RUNAS_T, line->cl_runas);
+ Save_str(fd, S_MAILTO_T, line->cl_mailto);
+ Save_strn(fd, S_OPTION_T, line->cl_option, OPTION_SIZE);
/* the following are saved only if needed */
if ( is_volatile(line->cl_option) && is_freq(line->cl_option) ) {
- Save_lint(f, S_FIRST_T, line->cl_first);
+ Save_lint(fd, S_FIRST_T, line->cl_first);
}
else
- Save_lint(f, S_NEXTEXE_T, line->cl_nextexe);
+ Save_lint(fd, S_NEXTEXE_T, line->cl_nextexe);
if ( line->cl_numexe )
- Save_strn(f, S_NUMEXE_T, &line->cl_numexe, 1);
+ Save_strn(fd, S_NUMEXE_T, &line->cl_numexe, 1);
if ( is_lavg(line->cl_option) )
- Save_strn(f, S_LAVG_T, line->cl_lavg, LAVG_SIZE);
+ Save_strn(fd, S_LAVG_T, line->cl_lavg, LAVG_SIZE);
if ( line->cl_until > 0 )
- Save_lint(f, S_UNTIL_T, line->cl_until);
+ Save_lint(fd, S_UNTIL_T, line->cl_until);
if ( line->cl_nice != 0 )
- Save_strn(f, S_NICE_T, &line->cl_nice, 1);
+ Save_strn(fd, S_NICE_T, &line->cl_nice, 1);
if ( line->cl_runfreq > 0 ) {
- Save_lint(f, S_RUNFREQ_T, line->cl_runfreq);
- Save_lint(f, S_REMAIN_T, line->cl_remain);
+ Save_lint(fd, S_RUNFREQ_T, line->cl_runfreq);
+ Save_lint(fd, S_REMAIN_T, line->cl_remain);
}
if ( is_freq(line->cl_option) ) {
/* save the frequency to run the line */
- Save_lint(f, S_TIMEFREQ_T, line->cl_timefreq)
+ Save_lint(fd, S_TIMEFREQ_T, line->cl_timefreq)
}
else {
/* save the time and date bit fields */
- Save_strn(f, S_MINS_T, line->cl_mins, bitstr_size(60));
- Save_strn(f, S_HRS_T, line->cl_hrs, bitstr_size(24));
- Save_strn(f, S_DAYS_T, line->cl_days, bitstr_size(32));
- Save_strn(f, S_MONS_T, line->cl_mons, bitstr_size(12));
- Save_strn(f, S_DOW_T, line->cl_dow, bitstr_size(8));
+ Save_strn(fd, S_MINS_T, line->cl_mins, bitstr_size(60));
+ Save_strn(fd, S_HRS_T, line->cl_hrs, bitstr_size(24));
+ Save_strn(fd, S_DAYS_T, line->cl_days, bitstr_size(32));
+ Save_strn(fd, S_MONS_T, line->cl_mons, bitstr_size(12));
+ Save_strn(fd, S_DOW_T, line->cl_dow, bitstr_size(8));
}
/* This field *must* be the last of each line */
- Save_type(f, S_ENDLINE_T);
+ Save_type(fd, S_ENDLINE_T);
}
- fclose(f);
+ close(fd);
if (arg_file != NULL)
/* we have to save only a single file */
* `LICENSE' that comes with the fcron source distribution.
*/
- /* $Id: convert-fcrontab.c,v 1.10 2002-02-25 18:45:06 thib Exp $ */
+ /* $Id: convert-fcrontab.c,v 1.11 2002-09-07 13:11:59 thib Exp $ */
#include "global.h"
#include "log.h"
#include "subs.h"
-char rcs_info[] = "$Id: convert-fcrontab.c,v 1.10 2002-02-25 18:45:06 thib Exp $";
+char rcs_info[] = "$Id: convert-fcrontab.c,v 1.11 2002-09-07 13:11:59 thib Exp $";
void info(void);
void usage(void);
}
/* error management */
-#define Save_type(file, type) \
+#define Save_type(fd, type) \
{ \
- if ( save_type(file, type) != OK ) { \
+ if ( save_type(fd, type) != OK ) { \
error_e("Could not write type : file has not been installed."); \
- fclose(file); \
+ close(fd); \
remove(buf); \
exit(EXIT_ERR); \
} \
}
-#define Save_str(file, type, str) \
+#define Save_str(fd, type, str) \
{ \
- if ( save_str(file, type, str) != OK ) { \
+ if ( save_str(fd, type, str) != OK ) { \
error_e("Could not write str : file has not been installed."); \
- fclose(file); \
+ close(fd); \
remove(buf); \
exit(EXIT_ERR); \
} \
}
-#define Save_strn(file, type, str, size) \
+#define Save_strn(fd, type, str, size) \
{ \
- if ( save_strn(file, type, str, size) != OK ) { \
+ if ( save_strn(fd, type, str, size) != OK ) { \
error_e("Could not write strn : file has not been installed."); \
- fclose(file); \
+ close(fd); \
remove(buf); \
exit(EXIT_ERR); \
} \
}
-#define Save_lint(file, type, value) \
+#define Save_lint(fd, type, value) \
{ \
- if ( save_lint(file, type, value) != OK ) { \
+ if ( save_lint(fd, type, value) != OK ) { \
error_e("Could not write lint : file has not been installed."); \
- fclose(file); \
+ close(fd); \
remove(buf); \
exit(EXIT_ERR); \
} \
CL *line = NULL;
env_t *env = NULL;
FILE *f = NULL;
+ int fd;
struct stat file_stat;
char buf[LINE_LEN];
time_t t_save = 0;
/* open a temp file in write mode and truncate it */
strcpy(buf, "tmp_");
strncat(buf, file_name, sizeof(buf) - sizeof("tmp_") - 1);
- if ( (f = fopen(buf, "w")) == NULL )
+ fd = open(buf, O_CREAT | O_TRUNC | O_SYNC);
+ if ( fd == -1 )
die_e("Could not open %s", buf);
- if ( fchown(fileno(f), file_stat.st_uid, file_stat.st_gid) != 0 )
+ if ( fchown(fd, file_stat.st_uid, file_stat.st_gid) != 0 )
die_e("Could not fchown %s", buf);
- if ( fchmod(fileno(f), file_stat.st_mode) != 0 )
+ if ( fchmod(fd, file_stat.st_mode) != 0 )
die_e("Could not fchmod %s", buf);
- Save_lint(f, S_HEADER_T, S_FILEVERSION );
- Save_str(f, S_USER_T, file->cf_user);
- Save_lint(f, S_TIMEDATE_T, t_save);
+ Save_lint(fd, S_HEADER_T, S_FILEVERSION );
+ Save_str(fd, S_USER_T, file->cf_user);
+ Save_lint(fd, S_TIMEDATE_T, t_save);
for (env = file->cf_env_base; env; env = env->e_next)
- Save_str(f, S_ENVVAR_T, env->e_val);
+ Save_str(fd, S_ENVVAR_T, env->e_val);
for (line = file->cf_line_base; line; line = line->cl_next) {
/* this ones are saved for every lines */
- Save_str(f, S_SHELL_T, line->cl_shell);
- Save_str(f, S_RUNAS_T, line->cl_runas);
- Save_str(f, S_MAILTO_T, line->cl_mailto);
- Save_lint(f, S_NEXTEXE_T, line->cl_nextexe);
- Save_strn(f, S_OPTION_T, line->cl_option, 3);
+ Save_str(fd, S_SHELL_T, line->cl_shell);
+ Save_str(fd, S_RUNAS_T, line->cl_runas);
+ Save_str(fd, S_MAILTO_T, line->cl_mailto);
+ Save_lint(fd, S_NEXTEXE_T, line->cl_nextexe);
+ Save_strn(fd, S_OPTION_T, line->cl_option, 3);
/* the following are saved only if needed */
if ( line->cl_numexe )
- Save_strn(f, S_NUMEXE_T, &line->cl_numexe, 1);
+ Save_strn(fd, S_NUMEXE_T, &line->cl_numexe, 1);
if ( is_lavg(line->cl_option) )
- Save_strn(f, S_LAVG_T, line->cl_lavg, 3);
+ Save_strn(fd, S_LAVG_T, line->cl_lavg, 3);
if ( line->cl_until > 0 )
- Save_lint(f, S_UNTIL_T, line->cl_until);
+ Save_lint(fd, S_UNTIL_T, line->cl_until);
if ( line->cl_nice != 0 )
- Save_strn(f, S_NICE_T, &line->cl_nice, 1);
+ Save_strn(fd, S_NICE_T, &line->cl_nice, 1);
if ( line->cl_runfreq > 0 ) {
- Save_lint(f, S_RUNFREQ_T, line->cl_runfreq);
- Save_lint(f, S_REMAIN_T, line->cl_remain);
+ Save_lint(fd, S_RUNFREQ_T, line->cl_runfreq);
+ Save_lint(fd, S_REMAIN_T, line->cl_remain);
}
if ( is_freq(line->cl_option) ) {
/* save the frequency to run the line */
- Save_lint(f, S_TIMEFREQ_T, line->cl_timefreq)
+ Save_lint(fd, S_TIMEFREQ_T, line->cl_timefreq)
}
else {
/* save the time and date bit fields */
- Save_strn(f, S_MINS_T, line->cl_mins, bitstr_size(60));
- Save_strn(f, S_HRS_T, line->cl_hrs, bitstr_size(24));
- Save_strn(f, S_DAYS_T, line->cl_days, bitstr_size(32));
- Save_strn(f, S_MONS_T, line->cl_mons, bitstr_size(12));
- Save_strn(f, S_DOW_T, line->cl_dow, bitstr_size(8));
+ Save_strn(fd, S_MINS_T, line->cl_mins, bitstr_size(60));
+ Save_strn(fd, S_HRS_T, line->cl_hrs, bitstr_size(24));
+ Save_strn(fd, S_DAYS_T, line->cl_days, bitstr_size(32));
+ Save_strn(fd, S_MONS_T, line->cl_mons, bitstr_size(12));
+ Save_strn(fd, S_DOW_T, line->cl_dow, bitstr_size(8));
}
/* This field *must* be the last of each line */
- Save_type(f, S_ENDLINE_T);
+ Save_type(fd, S_ENDLINE_T);
}
- fclose(f);
+ close(fd);
/* everything's ok : we can override the src file safely */
if ( rename(buf, file_name) != 0 )
* `LICENSE' that comes with the fcron source distribution.
*/
- /* $Id: fileconf.c,v 1.61 2002-08-30 20:05:39 thib Exp $ */
+ /* $Id: fileconf.c,v 1.62 2002-09-07 13:11:25 thib Exp $ */
#include "fcrontab.h"
/* save_file() error management */
-#define Save_type(file, type) \
+#define Save_type(fd, type) \
{ \
- if ( save_type(file, type) != OK ) { \
+ if ( save_type(fd, type) != OK ) { \
error_e("Could not write type : file has not been installed."); \
- fclose(file); \
+ close(fd); \
remove(path); \
return ERR; \
} \
}
-#define Save_str(file, type, str) \
+#define Save_str(fd, type, str) \
{ \
- if ( save_str(file, type, str) != OK ) { \
+ if ( save_str(fd, type, str) != OK ) { \
error_e("Could not write str : file has not been installed."); \
- fclose(file); \
+ close(fd); \
remove(path); \
return ERR; \
} \
}
-#define Save_strn(file, type, str, size) \
+#define Save_strn(fd, type, str, size) \
{ \
- if ( save_strn(file, type, str, size) != OK ) { \
+ if ( save_strn(fd, type, str, size) != OK ) { \
error_e("Could not write strn : file has not been installed."); \
- fclose(file); \
+ close(fd); \
remove(path); \
return ERR; \
} \
}
-#define Save_lint(file, type, value) \
+#define Save_lint(fd, type, value) \
{ \
- if ( save_lint(file, type, value) != OK ) { \
+ if ( save_lint(fd, type, value) != OK ) { \
error_e("Could not write lint : file has not been installed."); \
- fclose(file); \
+ close(fd); \
remove(path); \
return ERR; \
} \
{
CF *file = NULL;
CL *line = NULL;
- FILE *f = NULL;
+ int fd;
env_t *env = NULL;
if (debug_opt)
for (file = file_base; file; file = file->cf_next) {
/* open file */
- if ( (f = fopen(path, "w")) == NULL ) {
+ fd = open(path, O_CREAT | O_TRUNC | O_SYNC);
+ if ( fd == -1 ) {
error_e("Could not open %s : file has not be installed.", path);
return ERR;
}
* a file using a depreciated format generated by an old fcrontab,
* if the syntax has changed */
/* an binary fcrontab *must* start by such a header */
- Save_lint(f, S_HEADER_T, S_FILEVERSION );
+ Save_lint(fd, S_HEADER_T, S_FILEVERSION );
/* put the user's name : needed to check if his uid has not changed */
/* S_USER_T *must* be the 2nd field of a binary fcrontab */
- Save_str(f, S_USER_T, user);
+ Save_str(fd, S_USER_T, user);
/* put the time & date of saving : this is use for calcutating
* the system down time. As it is a new file, we set it to 0 */
/* S_USER_T *must* be the 3rd field of a binary fcrontab */
- Save_lint(f, S_TIMEDATE_T, 0);
+ Save_lint(fd, S_TIMEDATE_T, 0);
/* Save the time diff between local (real) and system hour (if any) */
if ( file->cf_tzdiff != 0 )
- Save_lint(f, S_TZDIFF_T, file->cf_tzdiff);
+ Save_lint(fd, S_TZDIFF_T, file->cf_tzdiff);
/* env variables, */
for (env = file->cf_env_base; env; env = env->e_next)
- Save_str(f, S_ENVVAR_T, env->e_val);
+ Save_str(fd, S_ENVVAR_T, env->e_val);
/* then, lines. */
for (line = file->cf_line_base; line; line = line->cl_next) {
/* this ones are saved for every lines */
- Save_str(f, S_SHELL_T, line->cl_shell);
- Save_str(f, S_RUNAS_T, line->cl_runas);
- Save_str(f, S_MAILTO_T, line->cl_mailto);
- Save_strn(f, S_OPTION_T, line->cl_option, OPTION_SIZE);
+ Save_str(fd, S_SHELL_T, line->cl_shell);
+ Save_str(fd, S_RUNAS_T, line->cl_runas);
+ Save_str(fd, S_MAILTO_T, line->cl_mailto);
+ Save_strn(fd, S_OPTION_T, line->cl_option, OPTION_SIZE);
/* the following are saved only if needed */
if ( line->cl_numexe )
- Save_strn(f, S_NUMEXE_T, &line->cl_numexe, 1);
+ Save_strn(fd, S_NUMEXE_T, &line->cl_numexe, 1);
if ( is_lavg(line->cl_option) )
- Save_strn(f, S_LAVG_T, line->cl_lavg, LAVG_SIZE);
+ Save_strn(fd, S_LAVG_T, line->cl_lavg, LAVG_SIZE);
if ( line->cl_until > 0 )
- Save_lint(f, S_UNTIL_T, line->cl_until);
+ Save_lint(fd, S_UNTIL_T, line->cl_until);
if ( line->cl_nice != 0 )
- Save_strn(f, S_NICE_T, &line->cl_nice, 1);
+ Save_strn(fd, S_NICE_T, &line->cl_nice, 1);
if ( line->cl_runfreq > 0 ) {
- Save_lint(f, S_RUNFREQ_T, line->cl_runfreq);
- Save_lint(f, S_REMAIN_T, line->cl_remain);
+ Save_lint(fd, S_RUNFREQ_T, line->cl_runfreq);
+ Save_lint(fd, S_REMAIN_T, line->cl_remain);
}
if ( is_freq(line->cl_option) ) {
/* save the frequency and the first wait time */
- Save_lint(f, S_FIRST_T, line->cl_first);
- Save_lint(f, S_TIMEFREQ_T, line->cl_timefreq);
+ Save_lint(fd, S_FIRST_T, line->cl_first);
+ Save_lint(fd, S_TIMEFREQ_T, line->cl_timefreq);
}
else {
/* save the time and date bit fields */
- Save_strn(f, S_MINS_T, line->cl_mins, bitstr_size(60));
- Save_strn(f, S_HRS_T, line->cl_hrs, bitstr_size(24));
- Save_strn(f, S_DAYS_T, line->cl_days, bitstr_size(32));
- Save_strn(f, S_MONS_T, line->cl_mons, bitstr_size(12));
- Save_strn(f, S_DOW_T, line->cl_dow, bitstr_size(8));
+ Save_strn(fd, S_MINS_T, line->cl_mins, bitstr_size(60));
+ Save_strn(fd, S_HRS_T, line->cl_hrs, bitstr_size(24));
+ Save_strn(fd, S_DAYS_T, line->cl_days, bitstr_size(32));
+ Save_strn(fd, S_MONS_T, line->cl_mons, bitstr_size(12));
+ Save_strn(fd, S_DOW_T, line->cl_dow, bitstr_size(8));
}
/* This field *must* be the last of each line */
{
- Save_type(f, S_ENDLINE_T);
+ Save_type(fd, S_ENDLINE_T);
}
}
- fclose(f);
+ close(fd);
}
return OK;
* `LICENSE' that comes with the fcron source distribution.
*/
- /* $Id: save.c,v 1.1 2002-02-25 18:45:18 thib Exp $ */
+ /* $Id: save.c,v 1.2 2002-09-07 13:12:10 thib Exp $ */
#include "global.h"
#include "save.h"
extern char debug_opt;
int
-save_type(FILE *f, short int type)
+save_type(int fd, 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;
+ if ( write(fd, &type, sizeof(type)) < sizeof(type) ) goto err;
+ if ( write(fd, &size, sizeof(size)) < sizeof(size) ) goto err;
return OK;
}
int
-save_str(FILE *f, short int type, char *str)
+save_str(int fd, 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;
+ if ( write(fd, &type, sizeof(type)) < sizeof(type) ) goto err;
+ if ( write(fd, &size, sizeof(size)) < sizeof(size) ) goto err;
+ if ( write(fd, str, size) < size ) goto err;
return OK;
}
int
-save_strn(FILE *f, short int type, char *str, short int size)
+save_strn(int fd, 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;
+ if ( write(fd, &type, sizeof(type)) < sizeof(type) ) goto err;
+ if ( write(fd, &size, sizeof(size)) < sizeof(size) ) goto err;
+ if ( write(fd, str, size) < size ) goto err;
return OK;
}
int
-save_lint(FILE *f, short int type, long int value)
+save_lint(int fd, 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;
+ if ( write(fd, &type, sizeof(type)) < sizeof(type) ) goto err;
+ if ( write(fd, &size, sizeof(size)) < sizeof(size) ) goto err;
+ if ( write(fd, &value, size) < size ) goto err;
return OK;
* `LICENSE' that comes with the fcron source distribution.
*/
- /* $Id: save.h,v 1.5 2002-02-25 18:45:51 thib Exp $ */
+ /* $Id: save.h,v 1.6 2002-09-07 13:12:13 thib Exp $ */
#ifndef __SAVE_H__
#define __SAVE_H__
/* functions defined by save.c */
-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);
+extern int save_type(int fd, short int type);
+extern int save_str(int fd, short int type, char *str);
+extern int save_strn(int fd, short int type, char *str, short int size);
+extern int save_lint(int fd, short int type, long int value);
/* here is the format fcron(tab) uses to save the fcrontabs :