Make code work in K&R compilers.

This commit is contained in:
2026-02-13 13:52:45 +00:00
parent 2645d50d42
commit fc6a0afc87
21 changed files with 257 additions and 13 deletions

View File

@@ -25,7 +25,11 @@ Copyright (C) 2011-2026 Natalia Portillo
#ifndef AARU_FSTESTER_SETTER_SRC_CONSTS_H
#define AARU_FSTESTER_SETTER_SRC_CONSTS_H
#if defined(__STDC__)
static const char* filenames[] = {
#else
static char *filenames[] = {
#endif
"FILNAM",
"FILNAM.EXT",
"FILENAME",
@@ -53,6 +57,7 @@ static const char* filenames[] = {
"This filename has fourty four characterrs",
"This filename has sixty three characters like a lazy dromedaire",
"This filename has sixty four characters like a redy lazy fox dog",
#if defined(__STDC__)
"This filename has one hundred twenty eight characters and once upon a time in a place which name you must buy the "
"book yetnotget",
"This filename has two hundred thirty six characters and once upon a time in a place which name i have no desire "
@@ -73,6 +78,7 @@ static const char* filenames[] = {
"This filename has two hundred fifty six characters and once upon a time in a place which name i have no desire to "
"call to mind there lived not long since one of those gentlemen that keep a lance and well you know it so go and "
"read the book as you must get",
#endif
"?NM?E?",
"N!A!M!",
"NA/ME",
@@ -98,6 +104,10 @@ static const char* filenames[] = {
0};
#define CLAUNIA_SIZE 7
#if defined(__STDC__)
static const unsigned char clauniaBytes[] = {0x43, 0x4C, 0x41, 0x55, 0x4E, 0x49, 0x41};
#else
static unsigned char clauniaBytes[] = {0x43, 0x4C, 0x41, 0x55, 0x4E, 0x49, 0x41};
#endif
#endif

View File

@@ -25,6 +25,7 @@ Copyright (C) 2011-2026 Natalia Portillo
#ifndef AARU_FSTESTER_SETTER_SRC_DEFS_H
#define AARU_FSTESTER_SETTER_SRC_DEFS_H
#if defined(__STDC__)
#include <stddef.h>
void GetOsInfo(void);
@@ -54,6 +55,36 @@ void MillionFiles(const char* path);
void DeleteFiles(const char* path);
void Links(const char* path);
#else
void GetOsInfo();
void GetVolumeInfo();
void FileAttributes();
void FilePermissions();
void ExtendedAttributes();
void ResourceFork();
void Filenames();
void Timestamps();
void DirectoryDepth();
void Fragmentation();
void Sparse();
void MillionFiles();
void DeleteFiles();
void Links();
#endif
#define FILENAME_FORMAT "This file should be named \"%s\".\n"

View File

@@ -23,19 +23,37 @@ Copyright (C) 2011-2026 Natalia Portillo
*****************************************************************************/
#include <errno.h>
#include <stdarg.h>
#include <stdio.h>
#include <time.h>
#include "log.h"
#if defined(__STDC__)
/* ANSI / ISO C */
#include <stdarg.h>
#define USE_ANSI_VARARGS 1
#else
/* XENIX / K&R C */
#include <varargs.h>
#endif
#include "log.h"
#include "main.h"
/* Thanks XENIX */
#if !defined(__STDC__) && !defined(COHERENT)
typedef long time_t;
#endif
static int log_opened;
static int log_quiet;
FILE* log_file;
#if defined(__STDC__)
int log_open(int quiet)
#else
int log_open(quiet)
int quiet;
#endif
{
time_t curtime;
@@ -64,6 +82,9 @@ int log_open(int quiet)
return 0;
}
#if USE_ANSI_VARARGS
/* ANSI version */
void log_write(const char* fmt, ...)
{
va_list args;
@@ -73,7 +94,6 @@ void log_write(const char* fmt, ...)
va_start(args, fmt);
vfprintf(log_file, fmt, args);
va_end(args);
fflush(log_file);
}
@@ -85,6 +105,36 @@ void log_write(const char* fmt, ...)
}
}
#else
/* XENIX K&R varargs version */
void log_write(va_alist)
va_dcl {
va_list args;
char *fmt;
va_start(args);
fmt = va_arg(args, char *);
if (log_opened) {
vfprintf(log_file, fmt, args);
fflush(log_file);
}
/* Restart varargs for console output */
va_end(args);
va_start(args);
fmt = va_arg(args, char *);
if (!log_quiet)
vprintf(fmt, args);
va_end(args);
}
#endif /* USE_ANSI_VARARGS */
void log_close()
{
time_t curtime;
@@ -103,7 +153,13 @@ void log_close()
log_quiet = 0;
}
#if defined(__STDC__)
void log_set_quiet(int quiet)
#else
void log_set_quiet(quiet)
int quiet;
#endif
{
log_file = NULL;
log_quiet = quiet;

View File

@@ -25,9 +25,19 @@ Copyright (C) 2011-2026 Natalia Portillo
#ifndef AARU_FSTESTER_SETTER_SRC_LOG_H_
#define AARU_FSTESTER_SETTER_SRC_LOG_H_
#if defined(__STDC__)
int log_open(int quiet);
void log_write(const char* fmt, ...);
void log_set_quiet(int quiet);
void log_close(void);
#else
int log_open();
void log_write();
void log_set_quiet();
void log_close();
#endif
#endif // AARU_FSTESTER_SETTER_SRC_LOG_H_

View File

@@ -22,7 +22,9 @@ Aaru Data Preservation Suite
Copyright (C) 2011-2026 Natalia Portillo
*****************************************************************************/
#if defined(__STDC__) /* XENIX again */
#include <stddef.h>
#endif
#include <stdio.h>
#include <string.h>
@@ -36,7 +38,14 @@ Copyright (C) 2011-2026 Natalia Portillo
#include <console.h>
#endif
#if defined(__STDC__)
int main(int argc, char** argv)
#else
int main(argc, argv)
int argc;
char *argv[];
#endif
{
size_t clusterSize = 0;
int i;

View File

@@ -32,7 +32,13 @@ Copyright (C) 2011-2026 Natalia Portillo
#include "bsd/bsd.h"
#endif
#if defined(__STDC__)
void FileAttributes(const char* path)
#else
void FileAttributes(path)
char *path;
#endif
{
#if defined(__linux__) || defined(__LINUX__) || defined(__gnu_linux)
LinuxFileAttributes(path);

View File

@@ -23,16 +23,25 @@ Copyright (C) 2011-2026 Natalia Portillo
*****************************************************************************/
#include <errno.h>
#if defined(__STDC__)
#include <stddef.h>
#endif
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include "../include/defs.h"
#include "../log.h"
#if defined(__STDC__)
void DeleteFiles(const char* path)
#else
void DeleteFiles(path)
char *path;
#endif
{
char filename[9];
long pos;

View File

@@ -25,13 +25,20 @@ Copyright (C) 2011-2026 Natalia Portillo
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include "../include/defs.h"
#include "../log.h"
#if defined(__STDC__)
void DirectoryDepth(const char* path)
#else
void DirectoryDepth(path)
char *path;
#endif
{
int ret;
char filename[9];
@@ -73,8 +80,8 @@ void DirectoryDepth(const char* path)
pos++;
// This can continue until the disk fills, the kernel crashes, or some other nasty success
if(pos >= 1000) break;
/* This can continue until the disk fills, the kernel crashes, or some other nasty success */
if (pos >= 100) break;
}
log_write("\tCreated %ld levels of directory hierarchy\n", pos);

View File

@@ -25,6 +25,7 @@ Copyright (C) 2011-2026 Natalia Portillo
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
@@ -32,7 +33,13 @@ Copyright (C) 2011-2026 Natalia Portillo
#include "../include/defs.h"
#include "../log.h"
#if defined(__STDC__)
void Filenames(const char* path)
#else
void Filenames(path)
char *path;
#endif
{
int ret;
FILE* h;

View File

@@ -23,16 +23,25 @@ Copyright (C) 2011-2026 Natalia Portillo
*****************************************************************************/
#include <errno.h>
#if defined(__STDC__)
#include <stddef.h>
#endif
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include "../include/defs.h"
#include "../log.h"
#if defined(__STDC__)
void MillionFiles(const char* path)
#else
void MillionFiles(path)
char *path;
#endif
{
char filename[9];
long pos = 0;

View File

@@ -23,10 +23,15 @@ Copyright (C) 2011-2026 Natalia Portillo
*****************************************************************************/
#include <errno.h>
#if defined(__STDC__)
#include <stddef.h>
#endif
#include <stdio.h>
#if defined(__STDC__)
#include <stdlib.h>
#endif
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
@@ -34,7 +39,12 @@ Copyright (C) 2011-2026 Natalia Portillo
#include "../include/defs.h"
#include "../log.h"
#if defined(__STDC__)
void Fragmentation(const char* path, size_t clusterSize)
#else
void Fragmentation(path, clusterSize)char* path;
size_t clusterSize;
#endif
{
size_t halfCluster = clusterSize / 2;
size_t quarterCluster = clusterSize / 4;

View File

@@ -23,15 +23,24 @@ Copyright (C) 2011-2026 Natalia Portillo
*****************************************************************************/
#include <errno.h>
#if defined(__STDC__)
#include <stddef.h>
#endif
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include "../include/defs.h"
#include "../log.h"
#if defined(__STDC__)
void Links(const char* path)
#else
void Links(path)
char path;
#endif
{
FILE* h;
int ret;

View File

@@ -24,6 +24,7 @@ Copyright (C) 2011-2026 Natalia Portillo
#include <errno.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
@@ -32,7 +33,13 @@ Copyright (C) 2011-2026 Natalia Portillo
#include "../include/defs.h"
#include "../log.h"
#if defined(__STDC__)
void FilePermissions(const char* path)
#else
void FilePermissions(path)
char *path;
#endif
{
int ret;
FILE* file;

View File

@@ -38,7 +38,11 @@ typedef struct
#define KNOWN_UNIX_PERMS 13
#if defined (__STDC__)
static const unix_perms_tests_t unix_perms[KNOWN_UNIX_PERMS] = {
#else
static unix_perms_tests_t unix_perms[KNOWN_UNIX_PERMS] = {
#endif
{"NONE", "File with no permissions", 0},
{"04000", "File with set-user-ID", 04000},
{"02000", "File with set-group-ID", 02000},

View File

@@ -28,10 +28,16 @@ Copyright (C) 2011-2026 Natalia Portillo
#include "darwin/darwin.h"
#endif
#if defined(__STDC__)
void ResourceFork(const char* path)
#else
void ResourceFork(path)
char *path;
#endif
{
#if defined(__APPLE__) && defined(__MACH__)
DarwinResourceFork(path);
#endif
// Not supported
/* Not supported */
}

View File

@@ -34,6 +34,7 @@ Copyright (C) 2011-2026 Natalia Portillo
#include <errno.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
@@ -41,7 +42,13 @@ Copyright (C) 2011-2026 Natalia Portillo
#include "../include/defs.h"
#include "../log.h"
#if defined(__STDC__)
void Sparse(const char* path)
#else
void Sparse(path)
char *path;
#endif
{
int ret;
int rc, wRc, cRc;

View File

@@ -31,19 +31,36 @@ Copyright (C) 2011-2026 Natalia Portillo
#endif
#include <errno.h>
#if defined(__STDC__)
#include <stddef.h>
#endif
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <utime.h>
#ifdef M_XENIX
#include <dos/sys/utime.h>
#else
# ifdef COHERENT
# include <sys/utime.h>
# else
# include <utime.h>
# endif
#endif
#include "time.h"
#include "../include/defs.h"
#include "../log.h"
#if defined(__STDC__)
void Timestamps(const char* path)
#else
void Timestamps(path)
char *path;
#endif
{
int ret;
FILE* h;

View File

@@ -48,7 +48,11 @@ typedef struct
#define KNOWN_UNIX_TIMES 10
#if defined(__STDC__)
static const unix_time_tests_t unix_times[KNOWN_UNIX_TIMES] = {
#else
static unix_time_tests_t unix_times[KNOWN_UNIX_TIMES] = {
#endif
"MAXATIME", MAXTIMESTAMP, 0, "access", MAXDATETIME,
"MAXMTIME", 0, MAXTIMESTAMP, "modification", MAXDATETIME,
"MINATIME", MINTIMESTAMP, 0, "access", MINDATETIME,

View File

@@ -23,7 +23,9 @@ Copyright (C) 2011-2026 Natalia Portillo
*****************************************************************************/
#include <errno.h>
#if defined(__STDC__)
#include <stddef.h>
#endif
#include <stdio.h>
#ifdef __NeXT__
@@ -36,15 +38,16 @@ Copyright (C) 2011-2026 Natalia Portillo
#define HAVE_STATFS_TYPE
#if NS_TARGET >= 42 // Rhapsody DR1
#if NS_TARGET >= 42 /* Rhapsody DR1 */
#define NEED_SYS_TYPES_H
#define HAVE_SYS_MOUNT_H
#define USE_STATFS_FTYPENAME
#else
#include <sys/vfs.h>
#endif // Rhapsody DR1
#endif /* Rhapsody DR1 */
#endif // __NeXT__
#endif /* __NeXT__ */
#ifdef HAVE_SYS_STATFS_H
#include <sys/statfs.h>
@@ -63,8 +66,8 @@ Copyright (C) 2011-2026 Natalia Portillo
#include <sys/types.h>
#endif
#include <sys/mount.h>
#include <sys/param.h>
#include <sys/mount.h>
#endif
#include "../include/defs.h"
@@ -79,7 +82,14 @@ Copyright (C) 2011-2026 Natalia Portillo
#include "bsd/bsd.h"
#endif
#if defined(__STDC__)
void GetVolumeInfo(const char* path, size_t* clusterSize)
#else
void GetVolumeInfo(path, clusterSize)
char *path;
size_t *clusterSize;
#endif
{
#ifdef HAVE_SYS_STATVFS_H
struct statvfs buf;
@@ -105,7 +115,8 @@ void GetVolumeInfo(const char* path, size_t* clusterSize)
#ifdef USE_STATFS_FTYPENAME
log_write("\tFilesystem: %s\n", buf.f_fstypename);
#elif defined(USE_STATFS_TYPE)
#else
# if defined(USE_STATFS_TYPE)
log_write("\tFilesystem: ");
switch(buf.f_type)
{
@@ -193,16 +204,24 @@ void GetVolumeInfo(const char* path, size_t* clusterSize)
default: log_write("unknown type -> 0x%lX", buf.f_type);
}
log_write("\n");
# endif
#endif
log_write("\tBytes per block: %ld\n", buf.f_bsize);
#if defined(__STDC__)
log_write("\tVolume size: %llu bytes\n", ((unsigned long long)buf.f_blocks) * buf.f_bsize);
log_write("\tVolume free: %llu bytes\n", ((unsigned long long)buf.f_bfree) * buf.f_bsize);
#else
log_write("\tVolume size: %lu bytes\n", ((unsigned long) buf.f_blocks) * buf.f_bsize);
log_write("\tVolume free: %lu bytes\n", ((unsigned long) buf.f_bfree) * buf.f_bsize);
#endif
#ifdef USE_STATFS_NAMELEN
log_write("\tMaximum component length: %ld\n", buf.f_namelen);
#elif USE_STATFS_NAMEMAX
#else
# if USE_STATFS_NAMEMAX
log_write("\tMaximum component length: %ld\n", buf.f_namemax);
# endif
#endif
#if HAVE_SYS_STATVFS_H
@@ -236,4 +255,5 @@ void GetVolumeInfo(const char* path, size_t* clusterSize)
#if defined(__APPLE__) && defined(__MACH__)
DarwinVolumeAttributes(path);
#endif
#endif /* M_XENIX */
}

View File

@@ -349,4 +349,4 @@ Copyright (C) 2011-2026 Natalia Portillo
#define _XIAFS_SUPER_MAGIC 0x012fd16d
#endif
#endif // AARU_FSTESTER_SETTER_UNIX_VOLUME_H
#endif /* AARU_FSTESTER_SETTER_UNIX_VOLUME_H */

View File

@@ -32,7 +32,13 @@ Copyright (C) 2011-2026 Natalia Portillo
#include "bsd/bsd.h"
#endif
#if defined(__STDC__)
void ExtendedAttributes(const char* path)
#else
void ExtendedAttributes(path)
char *path;
#endif
{
#if defined(__linux__) || defined(__LINUX__) || defined(__gnu_linux)
LinuxExtendedAttributes(path);