the format errors.
Closes #1318
ADD_DEFINITIONS(-D_XOPEN_SOURCE=500) # Ask wchar.h for mbstate_t
ENDIF()
+IF(MINGW)
+ ADD_DEFINITIONS(-D__USE_MINGW_ANSI_STDIO)
+ENDIF()
+
#
INCLUDE(CheckCSourceCompiles)
INCLUDE(CheckCSourceRuns)
* we know some option that will succeed.
*/
if (0 != systemf("%s --version >" DEV_NULL, testprog)) {
- failure("Unable to successfully run: %s --version\n", testprog, testprog);
+ failure("Unable to successfully run: %s --version\n", testprog);
assert(0);
}
*/
/* Regular file with 2 links. */
- failure(msg);
+ failure("%s", msg);
assertIsReg("file", 0644);
- failure(msg);
+ failure("%s", msg);
assertFileSize("file", 10);
- failure(msg);
+ failure("%s", msg);
assertFileNLinks("file", 2);
/* Another name for the same file. */
- failure(msg);
+ failure("%s", msg);
assertIsHardlink("linkfile", "file");
/* Symlink */
assertIsSymlink("symlink", "file", 0);
/* Another file with 1 link and different permissions. */
- failure(msg);
+ failure("%s", msg);
assertIsReg("file2", 0777);
- failure(msg);
+ failure("%s", msg);
assertFileSize("file2", 10);
- failure(msg);
+ failure("%s", msg);
assertFileNLinks("file2", 1);
/* dir */
gid = from_hex(e + 30, 8); /* gid */
assertEqualMem(e + 38, "00000003", 8); /* nlink */
t = from_hex(e + 46, 8); /* mtime */
- failure("t=0x%08x now=0x%08x=%d", t, now, now);
+ failure("t=%#08jx now=%#08jx=%jd", (intmax_t)t, (intmax_t)now,
+ (intmax_t)now);
assert(t <= now); /* File wasn't created in future. */
- failure("t=0x%08x now - 2=0x%08x = %d", t, now - 2, now - 2);
+ failure("t=%#08jx now - 2=%#08jx=%jd", (intmax_t)t, (intmax_t)now - 2,
+ (intmax_t)now - 2);
assert(t >= now - 2); /* File was created w/in last 2 secs. */
failure("newc format stores body only with last appearance of a link\n"
" first appearance should be empty, so this file size\n"
assertEqualInt(gid, from_hex(e + 30, 8)); /* gid */
assertEqualMem(e + 38, "00000001", 8); /* nlink */
t2 = from_hex(e + 46, 8); /* mtime */
- failure("First entry created at t=0x%08x this entry created at t2=0x%08x", t, t2);
+ failure("First entry created at t=%#08jx this entry created"
+ " at t2=%#08jx", (intmax_t)t, (intmax_t)t2);
assert(t2 == t || t2 == t + 1); /* Almost same as first entry. */
assertEqualMem(e + 54, "00000005", 8); /* File size */
fs = from_hex(e + 54, 8);
assertEqualInt(nlinks("dir"), from_hex(e + 38, 8)); /* nlinks */
#endif
t2 = from_hex(e + 46, 8); /* mtime */
- failure("First entry created at t=0x%08x this entry created at t2=0x%08x", t, t2);
+ failure("First entry created at t=%#08jx this entry created at"
+ "t2=%#08jx", (intmax_t)t, (intmax_t)t2);
assert(t2 == t || t2 == t + 1); /* Almost same as first entry. */
assertEqualMem(e + 54, "00000000", 8); /* File size */
fs = from_hex(e + 54, 8);
assertEqualInt(gid, from_hex(e + 30, 8)); /* gid */
assertEqualMem(e + 38, "00000003", 8); /* nlink */
t2 = from_hex(e + 46, 8); /* mtime */
- failure("First entry created at t=0x%08x this entry created at t2=0x%08x", t, t2);
+ failure("First entry created at t=%#08jx this entry created at"
+ "t2=%#08jx", (intmax_t)t, (intmax_t)t2);
assert(t2 == t || t2 == t + 1); /* Almost same as first entry. */
assertEqualInt(10, from_hex(e + 54, 8)); /* File size */
fs = from_hex(e + 54, 8);
size_t s;
extract_reference_file(refname);
- p = slurpfile(&s, refname);
+ p = slurpfile(&s, "%s", refname);
/* SFX files require seek support. */
assert((a = archive_read_new()) != NULL);
size_t s;
extract_reference_file(refname);
- p = slurpfile(&s, refname);
+ p = slurpfile(&s, "%s", refname);
/* Verify with seek support.
* Everything works correctly here. */
size_t s;
extract_reference_file(refname);
- p = slurpfile(&s, refname);
+ p = slurpfile(&s, "%s", refname);
assert((a = archive_read_new()) != NULL);
assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a));
int i;
extract_reference_file(refname);
- p = slurpfile(&s, refname);
+ p = slurpfile(&s, "%s", refname);
for (i = 1; i < 1000; ++i) {
assert((a = archive_read_new()) != NULL);
size_t s;
extract_reference_file(refname);
- p = slurpfile(&s, refname);
+ p = slurpfile(&s, "%s", refname);
assert((a = archive_read_new()) != NULL);
assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_zip(a));
for (i = 0; filesets[n].names[i] != NULL; ++i)
{
char *newraw;
- tmp = slurpfile(&size, filesets[n].names[i]);
+ tmp = slurpfile(&size, "%s",
+ filesets[n].names[i]);
newraw = realloc(rawimage, oldsize + size);
if (!assert(newraw != NULL))
{
assertA(0 == archive_read_support_filter_all(a));
assertA(0 == archive_read_open_memory(a, buff, BUFF_SIZE));
/* Restore first entry with _EXTRACT_PERM. */
- failure("Error reading first entry", i);
+ failure("Error reading first entry");
assertA(0 == archive_read_next_header(a, &ae));
assertA(0 == archive_read_extract(a, ae, ARCHIVE_EXTRACT_PERM));
/* Rest of entries get restored with no flags. */
* Any byte before the expected
* data must be NULL.
*/
- failure("%s: pad at offset %d "
- "should be zero", name, actual.o);
+ failure("%s: pad at offset %jd "
+ "should be zero", name,
+ (intmax_t)actual.o);
assertEqualInt(c, 0);
} else if (actual.o == expect.o) {
/*
verify_basic(a, 1);
/* Verify with streaming reader. */
- p = slurpfile(&s, refname);
+ p = slurpfile(&s, "%s", refname);
assert((a = archive_read_new()) != NULL);
assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a));
assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
verify_info_zip_ux(a, 1);
/* Verify with streaming reader. */
- p = slurpfile(&s, refname);
+ p = slurpfile(&s, "%s", refname);
assert((a = archive_read_new()) != NULL);
assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a));
assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
verify_extract_length_at_end(a, 1);
/* Verify extraction with streaming reader. */
- p = slurpfile(&s, refname);
+ p = slurpfile(&s, "%s", refname);
assert((a = archive_read_new()) != NULL);
assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a));
assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
struct archive_entry *ae;
extract_reference_file(refname);
- p = slurpfile(&s, refname);
+ p = slurpfile(&s, "%s", refname);
/* Symlinks can only be extracted with the seeking reader. */
assert((a = archive_read_new()) != NULL);
assertEqualIntA(a, ARCHIVE_OK, archive_read_free(a));
/* Verify with streaming reader. */
- p = slurpfile(&s, refname);
+ p = slurpfile(&s, "%s", refname);
assert((a = archive_read_new()) != NULL);
assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a));
assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
struct archive_entry *ae;
extract_reference_file(refname);
- p = slurpfile(&s, refname);
+ p = slurpfile(&s, "%s", refname);
/* Symlinks can only be extracted with the seeking reader. */
assert((a = archive_read_new()) != NULL);
assertEqualInt(ARCHIVE_OK, archive_read_free(a));
/* Verify with streaming reader. */
- p = slurpfile(&s, refname);
+ p = slurpfile(&s, "%s", refname);
assert((a = archive_read_new()) != NULL);
assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a));
assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
}
extract_reference_file(refname);
- p = slurpfile(&archive_size, refname);
+ p = slurpfile(&archive_size, "%s", refname);
assert((a = archive_read_new()) != NULL);
assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_zip(a));
char data[16];
extract_reference_file(refname);
- p = slurpfile(&s, refname);
+ p = slurpfile(&s, "%s", refname);
assert((a = archive_read_new()) != NULL);
assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_zip_seekable(a));
};
extract_reference_file(refname);
- p = slurpfile(&s, refname);
+ p = slurpfile(&s, "%s", refname);
/* Mac metadata can only be extracted with the seeking reader. */
assert((a = archive_read_new()) != NULL);
assertEqualIntA(a, ARCHIVE_OK, archive_read_free(a));
/* Verify with streaming reader. */
- p = slurpfile(&s, refname);
+ p = slurpfile(&s, "%s", refname);
assert((a = archive_read_new()) != NULL);
assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a));
assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
assertEqualInt(ARCHIVE_OK, archive_read_free(a));
/* Verify with streaming reader. */
- p = slurpfile(&s, refname);
+ p = slurpfile(&s, "%s", refname);
assert((a = archive_read_new()) != NULL);
assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a));
assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
struct archive_entry *ae;
extract_reference_file(refname);
- p = slurpfile(&s, refname);
+ p = slurpfile(&s, "%s", refname);
/* Inspect outer Zip */
assert((a = archive_read_new()) != NULL);
char data[16];
extract_reference_file(refname);
- p = slurpfile(&s, refname);
+ p = slurpfile(&s, "%s", refname);
assert((a = archive_read_new()) != NULL);
assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_zip_seekable(a));
struct archive_entry *ae;
extract_reference_file(refname);
- p = slurpfile(&s, refname);
+ p = slurpfile(&s, "%s", refname);
assert((a = archive_read_new()) != NULL);
assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_zip_seekable(a));
struct archive_entry *ae;
extract_reference_file(refname);
- p = slurpfile(&s, refname);
+ p = slurpfile(&s, "%s", refname);
/* Symlinks can only be extracted with the seeking reader. */
assert((a = archive_read_new()) != NULL);
struct archive_entry *ae;
extract_reference_file(refname);
- p = slurpfile(&s, refname);
+ p = slurpfile(&s, "%s", refname);
assert((a = archive_read_new()) != NULL);
assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_zip_seekable(a));
size_t s;
extract_reference_file(refname);
- p = slurpfile(&s, refname);
+ p = slurpfile(&s, "%s", refname);
/* First read with seeking. */
assert((a = archive_read_new()) != NULL);
size_t s;
extract_reference_file(refname);
- p = slurpfile(&s, refname);
+ p = slurpfile(&s, "%s", refname);
/* First read with seeking. */
assert((a = archive_read_new()) != NULL);
assertEqualIntA(a, ARCHIVE_FATAL, archive_read_next_header(a, &ae));
goto wrap_up;
} else {
- failure("Archive truncated to %d bytes", i);
+ failure("Archive truncated to %zu bytes", i);
assertEqualIntA(a, 0, archive_read_next_header(a, &ae));
}
assertEqualIntA(a, ARCHIVE_FATAL, archive_read_data(a, filedata, filedata_size));
goto wrap_up;
} else {
- failure("Archive truncated to %d bytes", i);
+ failure("Archive truncated to %zu bytes", i);
assertEqualIntA(a, filedata_size,
archive_read_data(a, filedata, filedata_size));
}
* does not return an error if it can't consume
* it.) */
if (i < 1536 + 512*((filedata_size + 511)/512) + 512) {
- failure("i=%d minsize=%d", i,
+ failure("i=%zu minsize=%zu", i,
1536 + 512*((filedata_size + 511)/512) + 512);
assertEqualIntA(a, ARCHIVE_FATAL,
archive_read_next_header(a, &ae));
for (i = 0; i < 100; i++) {
sprintf(path, "%s%d", compression, i);
archive_entry_copy_pathname(ae, path);
- failure(path);
+ failure("%s", path);
if (!assertEqualIntA(a, ARCHIVE_OK,
archive_write_header(a, ae))) {
archive_write_free(a);
for (j = 0; j < (int)datasize; ++j) {
data[j] = (char)(rand() % 256);
}
- failure(path);
+ failure("%s", path);
if (!assertEqualIntA(a, datasize,
archive_write_data(a, data, datasize))) {
archive_write_free(a);
assert(sparse->type == END);
assertEqualInt(expected_offset, archive_entry_size(ae));
- failure(path);
+ failure("%s", path);
assertEqualInt(holes_seen, expected_holes);
assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
/* Verify the number of holes only, not its offset nor its
* length because those alignments are deeply dependence on
* its filesystem. */
- failure(path);
+ failure("%s", path);
assertEqualInt(blocks, archive_entry_sparse_count(ae));
archive_entry_free(ae);
}
#if !defined(_WIN32) || defined(__CYGWIN__)
assertEqualInt(st.st_mode, (archive_entry_mode(ae) & ~UMASK));
#endif
- failure(msg);
+ failure("%s", msg);
assertEqualInt(st.st_size, sizeof(data));
}
assertEqualIntA(a, ARCHIVE_OK, archive_write_close(a));
assertEqualInt(ARCHIVE_OK, archive_write_free(a));
- failure("Empty cpio archive should be exactly 87 bytes, was %d.", used);
+ failure("Empty cpio archive should be exactly 87 bytes, was %zu.", used);
assert(used == 87);
failure("Empty cpio archive is incorrectly formatted.");
assertEqualMem(buff, ref, 87);
assertEqualIntA(a, ARCHIVE_OK, archive_write_close(a));
assertEqualInt(ARCHIVE_OK, archive_write_free(a));
- failure("Empty shar archive should be exactly 0 bytes, was %d.", used);
+ failure("Empty shar archive should be exactly 0 bytes, was %zu.", used);
assert(used == 0);
}
/* This calculation gives "the smallest multiple of
* the block size that is at least 2048 bytes". */
- failure("blocksize=%d", blocksize);
+ failure("blocksize=%zu", blocksize);
assertEqualInt(((2048 - 1)/blocksize+1)*blocksize, used);
/*
/* This calculation gives "the smallest multiple of
* the block size that is at least 11264 bytes". */
- failure("blocksize=%d", blocksize);
+ failure("blocksize=%zu", blocksize);
assertEqualInt(((11264 - 1)/blocksize+1)*blocksize, used);
/*
/* This calculation gives "the smallest multiple of
* the block size that is at least 11264 bytes". */
- failure("blocksize=%d", blocksize);
+ failure("blocksize=%zu", blocksize);
assertEqualInt(((11264 - 1)/blocksize+1)*blocksize, used);
/*
#if defined(__GNUC__) && (__GNUC__ > 2 || \
(__GNUC__ == 2 && __GNUC_MINOR__ >= 7))
-#define __LA_PRINTFLIKE(f,a) __attribute__((__format__(__printf__, f, a)))
+# ifdef __MINGW_PRINTF_FORMAT
+# define __LA_PRINTF_FORMAT __MINGW_PRINTF_FORMAT
+# else
+# define __LA_PRINTF_FORMAT __printf__
+# endif
+# define __LA_PRINTFLIKE(f,a) __attribute__((__format__(__LA_PRINTF_FORMAT, f, a)))
#else
-#define __LA_PRINTFLIKE(f,a)
+# define __LA_PRINTFLIKE(f,a)
#endif
void lafe_warnc(int code, const char *fmt, ...) __LA_PRINTFLIKE(2, 3);
/* Use the tar program to create an archive. */
r = systemf("%s cf - %s %s >%s/archive 2>%s/pack.err", testprog, pack_options, flist, target, target);
- failure("Error invoking %s cf -", testprog, pack_options);
+ failure("Error invoking %s cf -%s", testprog, pack_options);
assertEqualInt(r, 0);
assertChdir(target);
continue;
switch(dp[0]) {
case 'l': case 'm': case 'd':
- failure("strlen(p)=%d", strlen(p));
+ failure("strlen(p)=%zu", strlen(p));
assert(strlen(p) < limit);
assertEqualString(p,
filenames[strlen(p)]);
break;
case 'f': case 's':
- failure("strlen(p)=%d", strlen(p));
+ failure("strlen(p)=%zu", strlen(p));
assert(strlen(p) < limit + 1);
assertEqualString(p,
filenames[strlen(p)]);
assertMakeDir("test6", 0755);
assertChdir("test6");
r = systemf("%s -cf archive.tar -C XXX -C ../d1 file1 2>write.err",
- testprog, testworkdir);
+ testprog);
assert(r != 0);
assertNonEmptyFile("write.err");
assertEqualInt(0,
* Test 5: Name-switching substitutions when extracting archive.
*/
assertMakeDir("test5", 0755);
- systemf("%s -cf test5.tar in/d1/foo in/d1/bar",
- testprog, testprog);
- systemf("%s -xf test5.tar -s /foo/bar/ -s }bar}foo} -C test5",
- testprog, testprog);
+ systemf("%s -cf test5.tar in/d1/foo in/d1/bar", testprog);
+ systemf("%s -xf test5.tar -s /foo/bar/ -s }bar}foo} -C test5", testprog);
assertFileContents("foo", 3, "test5/in/d1/bar");
assertFileContents("bar", 3, "test5/in/d1/foo");
#pragma warn -8068 /* Constant out of range in comparison. */
#endif
+
+#if defined(__GNUC__) && (__GNUC__ > 2 || \
+ (__GNUC__ == 2 && __GNUC_MINOR__ >= 7))
+# ifdef __MINGW_PRINTF_FORMAT
+# define __LA_PRINTF_FORMAT __MINGW_PRINTF_FORMAT
+# else
+# define __LA_PRINTF_FORMAT __printf__
+# endif
+# define __LA_PRINTFLIKE(f,a) __attribute__((__format__(__LA_PRINTF_FORMAT, f, a)))
+#else
+# define __LA_PRINTFLIKE(f,a)
+#endif
+
/* Haiku OS and QNX */
#if defined(__HAIKU__) || defined(__QNXNTO__)
/* Haiku and QNX have typedefs in stdint.h (needed for int64_t) */
skipping_setup(__FILE__, __LINE__);test_skipping
/* Function declarations. These are defined in test_utility.c. */
-void failure(const char *fmt, ...);
+void failure(const char *fmt, ...) __LA_PRINTFLIKE(1, 2);
int assertion_assert(const char *, int, int, const char *, void *);
int assertion_chdir(const char *, int, const char *);
int assertion_compare_fflags(const char *, int, const char *, const char *,
int assertion_version(const char*, int, const char *, const char *);
void skipping_setup(const char *, int);
-void test_skipping(const char *fmt, ...);
+void test_skipping(const char *fmt, ...) __LA_PRINTFLIKE(1, 2);
/* Like sprintf, then system() */
-int systemf(const char * fmt, ...);
+int systemf(const char *fmt, ...) __LA_PRINTFLIKE(1, 2);
/* Delay until time() returns a value after this. */
void sleepUntilAfter(time_t);
/* Suck file into string allocated via malloc(). Call free() when done. */
/* Supports printf-style args: slurpfile(NULL, "%s/myfile", refdir); */
-char *slurpfile(size_t *, const char *fmt, ...);
+char *slurpfile(size_t *, const char *fmt, ...) __LA_PRINTFLIKE(2, 3);
/* Dump block of bytes to a file. */
void dumpfile(const char *filename, void *, size_t);
*/
static int log_console = 0;
static FILE *logfile;
-static void
+static void __LA_PRINTFLIKE(1, 0)
vlogprintf(const char *fmt, va_list ap)
{
#ifdef va_copy
#endif
}
-static void
+static void __LA_PRINTFLIKE(1, 2)
logprintf(const char *fmt, ...)
{
va_list ap;
const char *failed_filename;
/* Count this failure, setup up log destination and handle initial report. */
-static void
+static void __LA_PRINTFLIKE(3, 4)
failure_start(const char *filename, int line, const char *fmt, ...)
{
va_list ap;
logprintf("]");
logprintf(" (count %d", cnt);
if (n < 0) {
- logprintf(",unknown %d bytes", len);
+ logprintf(",unknown %zu bytes", len);
}
logprintf(")");
logprintf(" file=\"%s\"\n", fn);
if (n > 0) {
hexdump(contents, buff, n, 0);
- logprintf(" expected\n", fn);
+ logprintf(" expected\n");
hexdump(buff, contents, s, 0);
} else {
logprintf(" File empty, contents should be:\n");
}
} else if (filet != t || filet_nsec != nsec) {
failure_start(file, line,
- "File %s has %ctime %lld.%09lld, expected %lld.%09lld",
+ "File %s has %ctime %lld.%09lld, expected %ld.%09ld",
pathname, type, filet, filet_nsec, t, nsec);
failure_finish(NULL);
return (0);
r = my_GetFileInformationByName(pathname, &bhfi);
if (r != 0 && bhfi.nNumberOfLinks == (DWORD)nlinks)
return (1);
- failure_start(file, line, "File %s has %d links, expected %d",
- pathname, bhfi.nNumberOfLinks, nlinks);
+ failure_start(file, line, "File %s has %jd links, expected %d",
+ pathname, (intmax_t)bhfi.nNumberOfLinks, nlinks);
failure_finish(NULL);
return (0);
#else
r = lstat(pathname, &st);
if (r == 0 && (int)st.st_nlink == nlinks)
return (1);
- failure_start(file, line, "File %s has %d links, expected %d",
- pathname, st.st_nlink, nlinks);
+ failure_start(file, line, "File %s has %jd links, expected %d",
+ pathname, (intmax_t)st.st_nlink, nlinks);
failure_finish(NULL);
return (0);
#endif
acls[i].qual, acls[i].name);
if (r != 0) {
ret = 1;
- failure_start(file, line, "type=%#010x, ",
+ failure_start(file, line, "type=%#010x, "
"permset=%#010x, tag=%d, qual=%d name=%s",
acls[i].type, acls[i].permset, acls[i].tag,
acls[i].qual, acls[i].name);