Changeset: c928d49407c8 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=c928d49407c8
Modified Files:
gdk/gdk_logger.c
Branch: default
Log Message:
Use sizeof(var) instead of repeating the constant with which var was declared.
This makes changing the size of var easier.
diffs (210 lines):
diff --git a/gdk/gdk_logger.c b/gdk/gdk_logger.c
--- a/gdk/gdk_logger.c
+++ b/gdk/gdk_logger.c
@@ -819,7 +819,7 @@ logger_open(logger *lg)
{
char filename[BUFSIZ];
- snprintf(filename, BUFSIZ, "%s%s." LLFMT, lg->dir, LOGFILE, lg->id);
+ snprintf(filename, sizeof(filename), "%s%s." LLFMT, lg->dir, LOGFILE,
lg->id);
lg->log = open_wstream(filename);
lg->end = 0;
@@ -984,13 +984,13 @@ logger_readlogs(logger *lg, FILE *fp, ch
if (lg->debug & 1)
fprintf(stderr, "#logger_readlogs %s\n", filename);
- while (fgets(id, BUFSIZ, fp) != NULL) {
+ while (fgets(id, sizeof(id), fp) != NULL) {
char buf[BUFSIZ];
lng lid = strtoll(id, NULL, 10);
if (lid >= lg->id) {
lg->id = lid;
- snprintf(buf, BUFSIZ, "%s." LLFMT, filename, lg->id);
+ snprintf(buf, sizeof(buf), "%s." LLFMT, filename,
lg->id);
if ((res = logger_readlog(lg, buf)) != 0) {
/* we cannot distinguish errors from
@@ -1163,7 +1163,7 @@ logger_new(int debug, const char *fn, co
lg->read32bitoid = 0;
#endif
- snprintf(filename, BUFSIZ, "%s%c%s%c", logdir, DIR_SEP, fn, DIR_SEP);
+ snprintf(filename, sizeof(filename), "%s%c%s%c", logdir, DIR_SEP, fn,
DIR_SEP);
if ((lg->fn = GDKstrdup(fn)) == NULL ||
(lg->dir = GDKstrdup(filename)) == NULL) {
fprintf(stderr, "!ERROR: logger_new: strdup failed\n");
@@ -1186,8 +1186,8 @@ logger_new(int debug, const char *fn, co
lg->seqs_val = NULL;
lg->dseqs = NULL;
- snprintf(filename, BUFSIZ, "%s%s", lg->dir, LOGFILE);
- snprintf(bak, BUFSIZ, "%s.bak", filename);
+ snprintf(filename, sizeof(filename), "%s%s", lg->dir, LOGFILE);
+ snprintf(bak, sizeof(bak), "%s.bak", filename);
/* try to open logfile backup, or failing that, the file
* itself. we need to know whether this file exists when
@@ -1201,10 +1201,10 @@ logger_new(int debug, const char *fn, co
}
fp = fopen(filename, "r");
- snprintf(bak, BUFSIZ, "%s_catalog", fn);
+ snprintf(bak, sizeof(bak), "%s_catalog", fn);
bid = BBPindex(bak);
- snprintf(bak, BUFSIZ, "%s_catalog_bid", fn);
+ snprintf(bak, sizeof(bak), "%s_catalog_bid", fn);
catalog_bid = BBPindex(bak);
if (bid != 0 && catalog_bid == 0)
@@ -1239,7 +1239,7 @@ logger_new(int debug, const char *fn, co
/* Make persistent */
bid = lg->catalog_bid->batCacheid;
BBPincref(bid, TRUE);
- snprintf(bak, BUFSIZ, "%s_catalog_bid", fn);
+ snprintf(bak, sizeof(bak), "%s_catalog_bid", fn);
if (BBPrename(lg->catalog_bid->batCacheid, bak) < 0)
logger_fatal("Logger_new: BBPrename to %s failed",
bak, 0, 0);
@@ -1247,14 +1247,14 @@ logger_new(int debug, const char *fn, co
/* Make persistent */
bid = lg->catalog_nme->batCacheid;
BBPincref(bid, TRUE);
- snprintf(bak, BUFSIZ, "%s_catalog_nme", fn);
+ snprintf(bak, sizeof(bak), "%s_catalog_nme", fn);
if (BBPrename(lg->catalog_nme->batCacheid, bak) < 0)
logger_fatal("Logger_new: BBPrename to %s failed",
bak, 0, 0);
bid = lg->dcatalog->batCacheid;
BBPincref(bid, TRUE);
- snprintf(bak, BUFSIZ, "%s_dcatalog", fn);
+ snprintf(bak, sizeof(bak), "%s_dcatalog", fn);
if (BBPrename(lg->dcatalog->batCacheid, bak) < 0)
logger_fatal("Logger_new: BBPrename to %s failed",
bak, 0, 0);
@@ -1298,19 +1298,18 @@ logger_new(int debug, const char *fn, co
if (b == 0)
logger_fatal("Logger_new: inconsistent database,
catalog does not exist", 0, 0, 0);
- snprintf(bak, BUFSIZ, "%s_catalog_nme", fn);
+ snprintf(bak, sizeof(bak), "%s_catalog_nme", fn);
catalog_nme = BBPindex(bak);
n = BATdescriptor(catalog_nme);
if (n == 0)
logger_fatal("Logger_new: inconsistent database,
catalog_nme does not exist", 0, 0, 0);
- snprintf(bak, BUFSIZ, "%s_dcatalog", fn);
+ snprintf(bak, sizeof(bak), "%s_dcatalog", fn);
dcatalog = BBPindex(bak);
d = BATdescriptor(dcatalog);
if (d == 0) {
d = logbat_new(TYPE_oid, BATSIZE, PERSISTENT);
BBPincref(d->batCacheid, TRUE);
- snprintf(bak, BUFSIZ, "%s_dcatalog", fn);
if (BBPrename(d->batCacheid, bak) < 0)
logger_fatal("Logger_new: BBPrename to %s
failed", bak, 0, 0);
}
@@ -1350,21 +1349,21 @@ logger_new(int debug, const char *fn, co
"sequences bat", 0, 0, 0);
lg->snapshots_bid = logbat_new(TYPE_int, 1, PERSISTENT);
- snprintf(bak, BUFSIZ, "%s_snapshots_bid", fn);
+ snprintf(bak, sizeof(bak), "%s_snapshots_bid", fn);
if (BBPrename(lg->snapshots_bid->batCacheid, bak) < 0)
logger_fatal("Logger_new: BBPrename to %s failed",
bak, 0, 0);
logger_add_bat(lg, lg->snapshots_bid, "snapshots_bid");
lg->snapshots_tid = logbat_new(TYPE_int, 1, PERSISTENT);
- snprintf(bak, BUFSIZ, "%s_snapshots_tid", fn);
+ snprintf(bak, sizeof(bak), "%s_snapshots_tid", fn);
if (BBPrename(lg->snapshots_tid->batCacheid, bak) < 0)
logger_fatal("Logger_new: BBPrename to %s failed",
bak, 0, 0);
logger_add_bat(lg, lg->snapshots_tid, "snapshots_tid");
lg->dsnapshots = logbat_new(TYPE_oid, 1, PERSISTENT);
- snprintf(bak, BUFSIZ, "%s_dsnapshots", fn);
+ snprintf(bak, sizeof(bak), "%s_dsnapshots", fn);
if (BBPrename(lg->dsnapshots->batCacheid, bak) < 0)
logger_fatal("Logger_new: BBPrename to %s failed",
bak, 0, 0);
@@ -1405,7 +1404,7 @@ logger_new(int debug, const char *fn, co
logger_fatal("Logger_new: inconsistent
database, snapshots_tid does not exist", 0, 0, 0);
} else {
lg->dsnapshots = logbat_new(TYPE_oid, 1, PERSISTENT);
- snprintf(bak, BUFSIZ, "%s_dsnapshots", fn);
+ snprintf(bak, sizeof(bak), "%s_dsnapshots", fn);
if (BBPrename(lg->dsnapshots->batCacheid, bak) < 0)
logger_fatal("Logger_new: BBPrename to %s
failed", bak, 0, 0);
logger_add_bat(lg, lg->dsnapshots, "dsnapshots");
@@ -1415,7 +1414,7 @@ logger_new(int debug, const char *fn, co
if (lg->freed == NULL)
logger_fatal("Logger_new: failed to create freed bat", 0, 0, 0);
BATseqbase(lg->freed, 0);
- snprintf(bak, BUFSIZ, "%s_freed", fn);
+ snprintf(bak, sizeof(bak), "%s_freed", fn);
if (BBPrename(lg->freed->batCacheid, bak) < 0)
logger_fatal("Logger_new: BBPrename to %s failed",
bak, 0, 0);
@@ -1611,7 +1610,7 @@ logger_exit(logger *lg)
return LOG_ERR;
}
- snprintf(filename, BUFSIZ, "%s%s", lg->dir, LOGFILE);
+ snprintf(filename, sizeof(filename), "%s%s", lg->dir, LOGFILE);
if ((fp = fopen(filename, "w")) != NULL) {
char ext[BUFSIZ];
@@ -1636,7 +1635,7 @@ logger_exit(logger *lg)
/* atomic action, switch to new log, keep old for
* later cleanup actions */
- snprintf(ext, BUFSIZ, "bak-" LLFMT, lg->id);
+ snprintf(ext, sizeof(ext), "bak-" LLFMT, lg->id);
if (GDKmove(0, lg->dir, LOGFILE, "bak", lg->dir, LOGFILE, ext)
< 0) {
fprintf(stderr, "!ERROR: logger_exit: rename %s.bak to
%s.%s failed\n",
@@ -1672,7 +1671,7 @@ logger_cleanup(logger *lg)
char id[BUFSIZ];
FILE *fp = NULL;
- snprintf(buf, BUFSIZ, "%s%s.bak-" LLFMT, lg->dir, LOGFILE, lg->id);
+ snprintf(buf, sizeof(buf), "%s%s.bak-" LLFMT, lg->dir, LOGFILE, lg->id);
if (lg->debug & 1)
fprintf(stderr, "#logger_cleanup %s\n", buf);
@@ -1683,10 +1682,10 @@ logger_cleanup(logger *lg)
}
/* skip catalog */
- while (fgets(id, BUFSIZ, fp) != NULL && id[0] != '\n')
+ while (fgets(id, sizeof(id), fp) != NULL && id[0] != '\n')
;
- while (fgets(id, BUFSIZ, fp) != NULL) {
+ while (fgets(id, sizeof(id), fp) != NULL) {
char *e = strchr(id, '\n');
if (e)
@@ -1694,7 +1693,7 @@ logger_cleanup(logger *lg)
GDKunlink(0, lg->dir, LOGFILE, id);
}
fclose(fp);
- snprintf(buf, BUFSIZ, "bak-" LLFMT, lg->id);
+ snprintf(buf, sizeof(buf), "bak-" LLFMT, lg->id);
GDKunlink(0, lg->dir, LOGFILE, buf);
@@ -1798,7 +1797,7 @@ log_bat_persists(logger *lg, BAT *b, con
if (!havevoid && b->ttype == TYPE_void && BATtdense(b)) {
ta = "vid";
}
- len = snprintf(buf, BUFSIZ, "%s,%s", ha, ta);
+ len = snprintf(buf, sizeof(buf), "%s,%s", ha, ta);
len++; /* include EOS */
if (!mnstr_writeInt(lg->log, len) ||
mnstr_write(lg->log, buf, 1, len) != (ssize_t) len) {
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list