Move error codes to separate header file

This commit is contained in:
Dietrich Epp 2022-04-22 11:36:17 -04:00
parent 3f6acc9f42
commit 61e4168fbc
7 changed files with 28 additions and 20 deletions

View File

@ -6,6 +6,7 @@
/* convert.h - character set conversion routines. */
#include "lib/defs.h"
#include "lib/error.h"
enum {
/* Constants for CR and LF. Note that we should not use '\n' or '\r'

View File

@ -12,6 +12,7 @@ cc_library(
"crc32.h",
"defs.h",
"endian.h",
"error.h",
"util.h",
],
copts = COPTS,

View File

@ -90,25 +90,6 @@ typedef long Size;
#endif
// =============================================================================
// Error codes and error reporting
// =============================================================================
// Error codes.
typedef enum {
// No error (success). Equal to 0.
kErrorOK,
// Memory allocation failed.
kErrorNoMemory,
// Invaild table data.
kErrorBadData,
// Too many files in one directory.
kErrorDirectoryTooLarge
} ErrorCode;
// =============================================================================
// Memory allocation
// =============================================================================

22
lib/error.h Normal file
View File

@ -0,0 +1,22 @@
// 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.
#ifndef LIB_ERROR_H
#define LIB_ERROR_H
// Error codes.
typedef enum {
// No error (success). Equal to 0.
kErrorOK,
// Memory allocation failed.
kErrorNoMemory,
// Invaild table data.
kErrorBadData,
// Too many files in one directory.
kErrorDirectoryTooLarge,
} ErrorCode;
#endif

View File

@ -6,6 +6,7 @@
// test.h - unit testing definitions.
#include "lib/defs.h"
#include "lib/error.h"
// The number of test failures.
extern int gFailCount;

View File

@ -3,7 +3,7 @@
// Mozilla Public License, version 2.0. See LICENSE.txt for details.
#ifndef LIB_UTIL_H
#define LIB_UTIL_H
#include "lib/defs.h"
#include "lib/error.h"
// Print an error message and exit.
void Fatalf(const char *msg, ...)

View File

@ -3,6 +3,8 @@
// Mozilla Public License, version 2.0. See LICENSE.txt for details.
#include "sync/tree.h"
#include "lib/error.h"
#include <stdio.h>
#define GetNode(nodes, ref) ((nodes) + (ref)-1)