mirror of
https://github.com/depp/syncfiles.git
synced 2025-02-19 20:30:39 +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",
|
||||
"includePath": ["${workspaceFolder}"],
|
||||
"cStandard": "c89",
|
||||
"cStandard": "c11",
|
||||
"intelliSenseMode": "linux-clang-x64",
|
||||
"compilerPath": "/usr/bin/clang"
|
||||
}
|
||||
|
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
@ -3,6 +3,9 @@
|
||||
"editor.detectIndentation": false,
|
||||
"editor.tabSize": 4,
|
||||
"editor.insertSpaces": false,
|
||||
"files.associations": {
|
||||
"*.h": "c"
|
||||
},
|
||||
"[starlark]": {
|
||||
"editor.insertSpaces": true
|
||||
},
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
#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);
|
||||
|
||||
#endif
|
||||
|
81
lib/defs.h
81
lib/defs.h
@ -3,34 +3,30 @@
|
||||
// Mozilla Public License, version 2.0. See LICENSE.txt for details.
|
||||
#ifndef 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_API_MAC_OS8 Targeting classic Mac OS (9.x and earlier)
|
||||
|
||||
TARGET_OS_MAC OS is some Macintosh variant (broadly speaking)
|
||||
TARGET_API_MAC_OS8 Targeting classic Mac OS (9.x and earlier)
|
||||
|
||||
TARGET_RT_LITTLE_ENDIAN Little-endian byte order
|
||||
TARGET_RT_BIG_ENDIAN Big-endian byte order
|
||||
TARGET_RT_LITTLE_ENDIAN Little-endian byte order
|
||||
TARGET_RT_BIG_ENDIAN Big-endian byte order
|
||||
*/
|
||||
#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>
|
||||
|
||||
#elif __APPLE__
|
||||
|
||||
/* Newer apple systems, including macOS >= 10. Header is in /usr/include, or
|
||||
within /usr/include inside the SDK. */
|
||||
// Newer apple systems, including macOS >= 10. Header is in /usr/include, or
|
||||
// within /usr/include inside the SDK.
|
||||
#include <TargetConditionals.h>
|
||||
|
||||
#else
|
||||
@ -51,9 +47,9 @@ Target information
|
||||
|
||||
#endif
|
||||
|
||||
/*==============================================================================
|
||||
Basic types
|
||||
==============================================================================*/
|
||||
// =============================================================================
|
||||
// Basic types
|
||||
// =============================================================================
|
||||
|
||||
#if TARGET_API_MAC_OS8
|
||||
|
||||
@ -61,7 +57,7 @@ Basic types
|
||||
|
||||
#else
|
||||
|
||||
/* Include <stddef.h> for NULL */
|
||||
// Include <stddef.h> for NULL.
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
@ -85,6 +81,8 @@ typedef uint16_t UInt16;
|
||||
typedef int16_t SInt16;
|
||||
typedef uint32_t UInt32;
|
||||
typedef int32_t SInt32;
|
||||
typedef uint64_t UInt64;
|
||||
typedef int64_t SInt64;
|
||||
|
||||
typedef char *Ptr;
|
||||
typedef Ptr *Handle;
|
||||
@ -92,28 +90,35 @@ typedef long Size;
|
||||
|
||||
#endif
|
||||
|
||||
/*==============================================================================
|
||||
Error codes and error reporting
|
||||
==============================================================================*/
|
||||
// =============================================================================
|
||||
// Error codes and error reporting
|
||||
// =============================================================================
|
||||
|
||||
/* Error codes. */
|
||||
// Error codes.
|
||||
typedef enum {
|
||||
/* No error. */
|
||||
// No error (success). Equal to 0.
|
||||
kErrorOK,
|
||||
|
||||
/* Memory allocation failed. */
|
||||
// Memory allocation failed.
|
||||
kErrorNoMemory,
|
||||
|
||||
/* Invaild table data. */
|
||||
// Invaild table data.
|
||||
kErrorBadData,
|
||||
|
||||
/* Too many files in one directory. */
|
||||
// Too many files in one directory.
|
||||
kErrorDirectoryTooLarge
|
||||
} 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
|
||||
|
||||
@ -121,23 +126,23 @@ Memory allocation
|
||||
|
||||
#else
|
||||
|
||||
/* Allocate a relocatable block of memory. */
|
||||
// Allocate a relocatable block of memory.
|
||||
Handle NewHandle(Size byteSize);
|
||||
|
||||
/* Free a relocatable block of memory. */
|
||||
// Free a relocatable block of memory.
|
||||
void DisposeHandle(Handle h);
|
||||
|
||||
#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);
|
||||
|
||||
/* Fill memory with zeroes. */
|
||||
// Fill memory with zeroes.
|
||||
void MemClear(void *ptr, Size size);
|
||||
|
||||
/*==============================================================================
|
||||
Assertions
|
||||
==============================================================================*/
|
||||
// =============================================================================
|
||||
// Assertions
|
||||
// =============================================================================
|
||||
|
||||
#if NDEBUG
|
||||
#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.
|
||||
#ifndef LIB_TEST_H
|
||||
#define LIB_TEST_H
|
||||
/* test.h - unit testing definitions. */
|
||||
// test.h - unit testing definitions.
|
||||
|
||||
#include "lib/defs.h"
|
||||
|
||||
/* The number of test failures. */
|
||||
// The number of test failures.
|
||||
extern int gFailCount;
|
||||
|
||||
/* Set the name of the current test. */
|
||||
// Set the name of the current test.
|
||||
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)));
|
||||
|
||||
/* Fail the current test. */
|
||||
// Fail the current test.
|
||||
void Failf(const char *msg, ...) __attribute__((format(printf, 1, 2)));
|
||||
|
||||
/* Return the description of an error code. Fatal error if the error code is
|
||||
invalid. */
|
||||
// Return the description of an error code. Fatal error if the error code is
|
||||
// invalid.
|
||||
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);
|
||||
|
||||
#endif
|
||||
|
@ -1,11 +1,8 @@
|
||||
// Copyright 2022 Dietrich Epp.
|
||||
// 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.
|
||||
/* toolbox.c - replacement functions for Mac OS toolbox functions
|
||||
|
||||
This is used to run conversion tests on non-Mac OS systems to make
|
||||
development easier. These are not intended to make it possible to port the
|
||||
converter to non-Mac OS systems. */
|
||||
// toolbox.c - replacement functions for Mac OS toolbox functions
|
||||
#include "lib/defs.h"
|
||||
#include "lib/util.h"
|
||||
|
||||
|
@ -5,12 +5,12 @@
|
||||
#define LIB_UTIL_H
|
||||
#include "lib/defs.h"
|
||||
|
||||
/* Print an error message and exit. */
|
||||
// Print an error message and exit.
|
||||
void Fatalf(const char *msg, ...)
|
||||
__attribute__((noreturn, format(printf, 1, 2)));
|
||||
|
||||
/* Return a basic description of the given error code, or NULL if the error code
|
||||
is unknown. */
|
||||
// Return a basic description of the given error code, or NULL if the error code
|
||||
// is unknown.
|
||||
const char *ErrorDescription(ErrorCode err);
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user