From: thib Date: Sat, 14 Apr 2007 16:59:02 +0000 (+0000) Subject: use fscanf(),fprintf(),etc size arguments dependent on the architecture X-Git-Tag: ver3_0_3-rc1~17 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d013a6b9a76f0916745d59f5d786eacd6ad1f5cf;p=fcron use fscanf(),fprintf(),etc size arguments dependent on the architecture --- diff --git a/config.h.in b/config.h.in index 03d9818..83e9088 100644 --- a/config.h.in +++ b/config.h.in @@ -21,7 +21,7 @@ * `LICENSE' that comes with the fcron source distribution. */ - /* $Id: config.h.in,v 1.60 2007-01-23 22:51:22 thib Exp $ */ + /* $Id: config.h.in,v 1.61 2007-04-14 17:02:34 thib Exp $ */ /* *********************************************************** */ @@ -407,3 +407,37 @@ #define O_SYNC O_FSYNC #endif +/* These SIZEOF_* constants are defined by the AC_CHECK_SIZEOF macro */ +#undef SIZEOF_TIME_T +#undef SIZEOF_PID_T +#undef SIZEOF_SHORT_INT +#undef SIZEOF_INT +#undef SIZEOF_LONG_INT +#undef SIZEOF_LONG_LONG_INT + +/* We need all these types in global.h to know which conversion string we whould + * use when reading a pid_t or a time_t */ +#ifndef SIZEOF_PID_T +#error "sizeof pid_t unknown." +#endif + +#ifndef SIZEOF_TIME_T +#error "sizeof time_t unknown." +#endif + +#ifndef SIZEOF_SHORT_INT +#error "sizeof short int unknown." +#endif + +#ifndef SIZEOF_INT +#error "sizeof int unknown." +#endif + +#ifndef SIZEOF_LONG_INT +#error "sizeof long int unknown." +#endif + +#ifndef SIZEOF_LONG_LONG_INT +#error "sizeof long long int unknown." +#endif + diff --git a/convert-fcrontab.c b/convert-fcrontab.c index 22b14b3..9591db7 100644 --- a/convert-fcrontab.c +++ b/convert-fcrontab.c @@ -22,12 +22,11 @@ * `LICENSE' that comes with the fcron source distribution. */ - /* $Id: convert-fcrontab.c,v 1.21 2006-05-20 16:27:46 thib Exp $ */ + /* $Id: convert-fcrontab.c,v 1.22 2007-04-14 17:03:00 thib Exp $ */ #include "convert-fcrontab.h" -#include "global.h" -char rcs_info[] = "$Id: convert-fcrontab.c,v 1.21 2006-05-20 16:27:46 thib Exp $"; +char rcs_info[] = "$Id: convert-fcrontab.c,v 1.22 2007-04-14 17:03:00 thib Exp $"; void info(void); void usage(void); @@ -185,7 +184,7 @@ convert_file(char *file_name) if ((file->cf_user = read_str(f, buf, sizeof(buf))) == NULL) die_e("Cannot read user's name"); - if ( fscanf(f, "%ld", (long int *) &t_save) != 1 ) + if ( fscanf(f, "%" ATTR_SIZE_TIMET "d", CAST_TIMET_PTR &t_save) != 1 ) error("could not get time and date of saving"); /* read env variables */ diff --git a/fcronsighup.c b/fcronsighup.c index 34eb01f..ea03361 100644 --- a/fcronsighup.c +++ b/fcronsighup.c @@ -21,13 +21,13 @@ * `LICENSE' that comes with the fcron source distribution. */ - /* $Id: fcronsighup.c,v 1.11 2007-01-01 18:49:43 thib Exp $ */ + /* $Id: fcronsighup.c,v 1.12 2007-04-14 16:59:02 thib Exp $ */ #include "fcronsighup.h" #include "global.h" #include "allow.h" -char rcs_info[] = "$Id: fcronsighup.c,v 1.11 2007-01-01 18:49:43 thib Exp $"; +char rcs_info[] = "$Id: fcronsighup.c,v 1.12 2007-04-14 16:59:02 thib Exp $"; void usage(void); void sig_daemon(void); @@ -83,7 +83,7 @@ read_pid(void) pid_t pid = 0; if ((fp = fopen(pidfile, "r")) != NULL) { - if ( fscanf(fp, "%d", (int *) &pid) < 1 ) + if ( fscanf(fp, "%" ATTR_SIZE_PIDT "d", CAST_PIDT_PTR &pid) < 1 ) error("Unable to read fcron daemon's pid (fscanf(fp,...))"); fclose(fp); } diff --git a/global.h b/global.h index 1cf25c7..b9d00cc 100644 --- a/global.h +++ b/global.h @@ -21,7 +21,7 @@ * `LICENSE' that comes with the fcron source distribution. */ - /* $Id: global.h,v 1.47 2007-01-23 22:49:03 thib Exp $ */ + /* $Id: global.h,v 1.48 2007-04-14 17:02:20 thib Exp $ */ /* @@ -234,6 +234,39 @@ typedef struct exe_t { } exe_t; +#if SIZEOF_TIME_T == SIZEOF_SHORT_INT +#define ATTR_SIZE_TIMET "h" +#define CAST_TIMET_PTR (short int *) +#elif SIZEOF_TIME_T == SIZEOF_INT +#define ATTR_SIZE_TIMET "" +#define CAST_TIMET_PTR (int *) +#elif SIZEOF_TIME_T == SIZEOF_LONG_INT +#define ATTR_SIZE_TIMET "l" +#define CAST_TIMET_PTR (long int *) +#elif SIZEOF_TIME_T == SIZEOF_LONG_LONG_INT +#define ATTR_SIZE_TIMET "ll" +#define CAST_TIMET_PTR (long long int *) +#else +#error "SIZEOF_TIME_T does not correspond with a known format." +#endif + +#if SIZEOF_PID_T == SIZEOF_SHORT_INT +#define ATTR_SIZE_PIDT "h" +#define CAST_PIDT_PTR (short int *) +#elif SIZEOF_PID_T == SIZEOF_INT +#define ATTR_SIZE_PIDT "" +#define CAST_PIDT_PTR (int *) +#elif SIZEOF_PID_T == SIZEOF_LONG_INT +#define ATTR_SIZE_PIDT "l" +#define CAST_PIDT_PTR (long int *) +#elif SIZEOF_PID_T == SIZEOF_LONG_LONG_INT +#define ATTR_SIZE_PIDT "ll" +#define CAST_PIDT_PTR (long long int *) +#else +#error "SIZEOF_PID_T does not correspond with a known format." +#endif + + /* local header files : we include here the headers which may use some types defined * above. */