mirror of
https://github.com/depp/syncfiles.git
synced 2024-06-14 11:29:28 +00:00
Use more modern C
While C99 is not supported by old Mac OS compilers, line comments are supported. Keeping strictly to old C90 style code is annoying without benefit.
This commit is contained in:
parent
054a4134e6
commit
3f6acc9f42
2
.vscode/c_cpp_properties.json
vendored
2
.vscode/c_cpp_properties.json
vendored
|
@ -3,7 +3,7 @@
|
||||||
{
|
{
|
||||||
"name": "Linux",
|
"name": "Linux",
|
||||||
"includePath": ["${workspaceFolder}"],
|
"includePath": ["${workspaceFolder}"],
|
||||||
"cStandard": "c89",
|
"cStandard": "c11",
|
||||||
"intelliSenseMode": "linux-clang-x64",
|
"intelliSenseMode": "linux-clang-x64",
|
||||||
"compilerPath": "/usr/bin/clang"
|
"compilerPath": "/usr/bin/clang"
|
||||||
}
|
}
|
||||||
|
|
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
|
@ -3,6 +3,9 @@
|
||||||
"editor.detectIndentation": false,
|
"editor.detectIndentation": false,
|
||||||
"editor.tabSize": 4,
|
"editor.tabSize": 4,
|
||||||
"editor.insertSpaces": false,
|
"editor.insertSpaces": false,
|
||||||
|
"files.associations": {
|
||||||
|
"*.h": "c"
|
||||||
|
},
|
||||||
"[starlark]": {
|
"[starlark]": {
|
||||||
"editor.insertSpaces": true
|
"editor.insertSpaces": true
|
||||||
},
|
},
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
#include "lib/defs.h"
|
#include "lib/defs.h"
|
||||||
|
|
||||||
/* Incrementally calculate a CRC32. This is the same CRC32 used by Gzip. */
|
// Incrementally calculate a CRC32. This is the same CRC32 used by Gzip.
|
||||||
UInt32 CRC32Update(UInt32 crc, const void *ptr, Size size);
|
UInt32 CRC32Update(UInt32 crc, const void *ptr, Size size);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
71
lib/defs.h
71
lib/defs.h
|
@ -3,17 +3,13 @@
|
||||||
// Mozilla Public License, version 2.0. See LICENSE.txt for details.
|
// Mozilla Public License, version 2.0. See LICENSE.txt for details.
|
||||||
#ifndef LIB_DEFS_H
|
#ifndef LIB_DEFS_H
|
||||||
#define LIB_DEFS_H
|
#define LIB_DEFS_H
|
||||||
/* defs.h - common definitions. */
|
// defs.h - common definitions.
|
||||||
|
|
||||||
/*==============================================================================
|
// =============================================================================
|
||||||
Target information
|
// Target information
|
||||||
==============================================================================*/
|
// =============================================================================
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Note that this code does not need to be especially portable. It just runs on
|
|
||||||
Mac OS and development systems (for testing). We can assume that the
|
|
||||||
development system has GCC.
|
|
||||||
|
|
||||||
Macros we care about:
|
Macros we care about:
|
||||||
|
|
||||||
TARGET_OS_MAC OS is some Macintosh variant (broadly speaking)
|
TARGET_OS_MAC OS is some Macintosh variant (broadly speaking)
|
||||||
|
@ -24,13 +20,13 @@ Target information
|
||||||
*/
|
*/
|
||||||
#if macintosh
|
#if macintosh
|
||||||
|
|
||||||
/* Classic Mac OS. Header is part of Universal Interfaces & Carbon. */
|
// Classic Mac OS. Header is part of Universal Interfaces & Carbon.
|
||||||
#include <ConditionalMacros.h>
|
#include <ConditionalMacros.h>
|
||||||
|
|
||||||
#elif __APPLE__
|
#elif __APPLE__
|
||||||
|
|
||||||
/* Newer apple systems, including macOS >= 10. Header is in /usr/include, or
|
// Newer apple systems, including macOS >= 10. Header is in /usr/include, or
|
||||||
within /usr/include inside the SDK. */
|
// within /usr/include inside the SDK.
|
||||||
#include <TargetConditionals.h>
|
#include <TargetConditionals.h>
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
@ -51,9 +47,9 @@ Target information
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*==============================================================================
|
// =============================================================================
|
||||||
Basic types
|
// Basic types
|
||||||
==============================================================================*/
|
// =============================================================================
|
||||||
|
|
||||||
#if TARGET_API_MAC_OS8
|
#if TARGET_API_MAC_OS8
|
||||||
|
|
||||||
|
@ -61,7 +57,7 @@ Basic types
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
/* Include <stddef.h> for NULL */
|
// Include <stddef.h> for NULL.
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
@ -85,6 +81,8 @@ typedef uint16_t UInt16;
|
||||||
typedef int16_t SInt16;
|
typedef int16_t SInt16;
|
||||||
typedef uint32_t UInt32;
|
typedef uint32_t UInt32;
|
||||||
typedef int32_t SInt32;
|
typedef int32_t SInt32;
|
||||||
|
typedef uint64_t UInt64;
|
||||||
|
typedef int64_t SInt64;
|
||||||
|
|
||||||
typedef char *Ptr;
|
typedef char *Ptr;
|
||||||
typedef Ptr *Handle;
|
typedef Ptr *Handle;
|
||||||
|
@ -92,28 +90,35 @@ typedef long Size;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*==============================================================================
|
// =============================================================================
|
||||||
Error codes and error reporting
|
// Error codes and error reporting
|
||||||
==============================================================================*/
|
// =============================================================================
|
||||||
|
|
||||||
/* Error codes. */
|
// Error codes.
|
||||||
typedef enum {
|
typedef enum {
|
||||||
/* No error. */
|
// No error (success). Equal to 0.
|
||||||
kErrorOK,
|
kErrorOK,
|
||||||
|
|
||||||
/* Memory allocation failed. */
|
// Memory allocation failed.
|
||||||
kErrorNoMemory,
|
kErrorNoMemory,
|
||||||
|
|
||||||
/* Invaild table data. */
|
// Invaild table data.
|
||||||
kErrorBadData,
|
kErrorBadData,
|
||||||
|
|
||||||
/* Too many files in one directory. */
|
// Too many files in one directory.
|
||||||
kErrorDirectoryTooLarge
|
kErrorDirectoryTooLarge
|
||||||
} ErrorCode;
|
} ErrorCode;
|
||||||
|
|
||||||
/*==============================================================================
|
// =============================================================================
|
||||||
Memory allocation
|
// Memory allocation
|
||||||
==============================================================================*/
|
// =============================================================================
|
||||||
|
|
||||||
|
/*
|
||||||
|
These functions are used to work with memory from code that runs on both
|
||||||
|
classic Mac OS systems and newer systems. Memory can be tight on very old
|
||||||
|
Mac systems, and to make the most of it, we only relocatable blocks of
|
||||||
|
memory (handles) whenever possible.
|
||||||
|
*/
|
||||||
|
|
||||||
#if TARGET_API_MAC_OS8
|
#if TARGET_API_MAC_OS8
|
||||||
|
|
||||||
|
@ -121,23 +126,23 @@ Memory allocation
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
/* Allocate a relocatable block of memory. */
|
// Allocate a relocatable block of memory.
|
||||||
Handle NewHandle(Size byteSize);
|
Handle NewHandle(Size byteSize);
|
||||||
|
|
||||||
/* Free a relocatable block of memory. */
|
// Free a relocatable block of memory.
|
||||||
void DisposeHandle(Handle h);
|
void DisposeHandle(Handle h);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Resize a relocatable block of memory. Return true on success. */
|
/// Resize a relocatable block of memory. Return true on success.
|
||||||
Boolean ResizeHandle(Handle h, Size newSize);
|
Boolean ResizeHandle(Handle h, Size newSize);
|
||||||
|
|
||||||
/* Fill memory with zeroes. */
|
// Fill memory with zeroes.
|
||||||
void MemClear(void *ptr, Size size);
|
void MemClear(void *ptr, Size size);
|
||||||
|
|
||||||
/*==============================================================================
|
// =============================================================================
|
||||||
Assertions
|
// Assertions
|
||||||
==============================================================================*/
|
// =============================================================================
|
||||||
|
|
||||||
#if NDEBUG
|
#if NDEBUG
|
||||||
#define assert(x) ((void)0)
|
#define assert(x) ((void)0)
|
||||||
|
|
16
lib/test.h
16
lib/test.h
|
@ -3,27 +3,27 @@
|
||||||
// Mozilla Public License, version 2.0. See LICENSE.txt for details.
|
// Mozilla Public License, version 2.0. See LICENSE.txt for details.
|
||||||
#ifndef LIB_TEST_H
|
#ifndef LIB_TEST_H
|
||||||
#define LIB_TEST_H
|
#define LIB_TEST_H
|
||||||
/* test.h - unit testing definitions. */
|
// test.h - unit testing definitions.
|
||||||
|
|
||||||
#include "lib/defs.h"
|
#include "lib/defs.h"
|
||||||
|
|
||||||
/* The number of test failures. */
|
// The number of test failures.
|
||||||
extern int gFailCount;
|
extern int gFailCount;
|
||||||
|
|
||||||
/* Set the name of the current test. */
|
// Set the name of the current test.
|
||||||
void SetTestName(const char *name);
|
void SetTestName(const char *name);
|
||||||
|
|
||||||
/* Set the name of the current test. */
|
// Set the name of the current test.
|
||||||
void SetTestNamef(const char *fmt, ...) __attribute__((format(printf, 1, 2)));
|
void SetTestNamef(const char *fmt, ...) __attribute__((format(printf, 1, 2)));
|
||||||
|
|
||||||
/* Fail the current test. */
|
// Fail the current test.
|
||||||
void Failf(const char *msg, ...) __attribute__((format(printf, 1, 2)));
|
void Failf(const char *msg, ...) __attribute__((format(printf, 1, 2)));
|
||||||
|
|
||||||
/* Return the description of an error code. Fatal error if the error code is
|
// Return the description of an error code. Fatal error if the error code is
|
||||||
invalid. */
|
// invalid.
|
||||||
const char *ErrorDescriptionOrDie(ErrorCode err);
|
const char *ErrorDescriptionOrDie(ErrorCode err);
|
||||||
|
|
||||||
/* Print information about completed tests and return the status code. */
|
// Print information about completed tests and return the status code.
|
||||||
int TestsDone(void);
|
int TestsDone(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,11 +1,8 @@
|
||||||
// Copyright 2022 Dietrich Epp.
|
// Copyright 2022 Dietrich Epp.
|
||||||
// This file is part of SyncFiles. SyncFiles is licensed under the terms of the
|
// This file is part of SyncFiles. SyncFiles is licensed under the terms of the
|
||||||
// Mozilla Public License, version 2.0. See LICENSE.txt for details.
|
// Mozilla Public License, version 2.0. See LICENSE.txt for details.
|
||||||
/* toolbox.c - replacement functions for Mac OS toolbox functions
|
|
||||||
|
|
||||||
This is used to run conversion tests on non-Mac OS systems to make
|
// toolbox.c - replacement functions for Mac OS toolbox functions
|
||||||
development easier. These are not intended to make it possible to port the
|
|
||||||
converter to non-Mac OS systems. */
|
|
||||||
#include "lib/defs.h"
|
#include "lib/defs.h"
|
||||||
#include "lib/util.h"
|
#include "lib/util.h"
|
||||||
|
|
||||||
|
|
|
@ -5,12 +5,12 @@
|
||||||
#define LIB_UTIL_H
|
#define LIB_UTIL_H
|
||||||
#include "lib/defs.h"
|
#include "lib/defs.h"
|
||||||
|
|
||||||
/* Print an error message and exit. */
|
// Print an error message and exit.
|
||||||
void Fatalf(const char *msg, ...)
|
void Fatalf(const char *msg, ...)
|
||||||
__attribute__((noreturn, format(printf, 1, 2)));
|
__attribute__((noreturn, format(printf, 1, 2)));
|
||||||
|
|
||||||
/* Return a basic description of the given error code, or NULL if the error code
|
// Return a basic description of the given error code, or NULL if the error code
|
||||||
is unknown. */
|
// is unknown.
|
||||||
const char *ErrorDescription(ErrorCode err);
|
const char *ErrorDescription(ErrorCode err);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue
Block a user