Files
fsnap/include/types.h
Fabio Scotto di Santolo 93e78fc7b3 Cosmetic cleanups across the tree
No behavioural change; verified byte-identical scan output over
/usr/include and /etc and byte-identical snapshots against the previous
build, with valgrind clean on every command.

- free() accepts NULL, so drop six guards around it in types.c.
- RecordObjectRelease returned an int no caller ever read; make it void,
  which is the idiom for a free-like function.
- RecordObjectFieldName bounded its index only from above. The underlying
  type of an enum is the compiler's choice, so compare as unsigned and
  catch a negative value too.
- copy() opened the destination "w+" but never reads it back; "w" says
  what it does.
- Testing strlen(s) == 0 walks the whole string to answer a question
  about its first byte.
- Two comments contradicted the code: split_record finds eight
  separators, not six, and strconcat explains itself in terms of a strcat
  it does not call.
- Drop includes nothing uses: <inttypes.h> from list.c and create.c, and
  <string.h> from list.c and from scan.c, which stopped needing it once
  the strlen above was gone.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018KyCHPAxWzqa3vHKdXJkgx
2026-08-26 15:37:57 +02:00

64 lines
2.3 KiB
C

#ifndef TYPES_H
#define TYPES_H
#include <inttypes.h>
#include <stdio.h>
enum Fields {
FILE_TYPE,
PERMISSIONS,
UID,
GID,
SIZE,
TIME,
TARGET,
FINGERPRINT,
PATH,
NONE,
};
const char *RecordObjectFieldName(enum Fields f);
struct RecordObject;
/* Allocate a new RecordObject. Returns NULL on allocation failure,
with errno set to ENOMEM. */
struct RecordObject *RecordObjectNew(void);
/* Unpack a pipe-delimited record string into self.
Returns 0 on success, -1 on failure. On failure errno is EINVAL when the
record is malformed and something else, ENOMEM in practice, when the
failure is the parser's own; only in the first case is *err meaningful.
If err is non-NULL and the offending field could be identified, sets *err
to that field. */
int RecordObjectUnpack(struct RecordObject *self, char *s, enum Fields *err);
/* Populate self by stat-ing the file at path and writing to out.
Returns the number of bytes written on success, -1 on failure. */
int RecordObjectWrite(struct RecordObject *self, const char *path, FILE *out);
/* Compare two RecordObjects field by field.
Returns 0 if equal, and an ordering like strcmp otherwise: negative if self
sorts first, positive if other does. On NULL self returns 128 and on NULL
other 1; those are ordering sentinels, unrelated to the FSNAP_EPARSE command
status that happens to share the value.
If err is non-NULL, sets *err to the first differing field. */
int RecordObjectCompare(const struct RecordObject *self,
const struct RecordObject *other, enum Fields *err);
/* Accessors */
char RecordObjectFileType(const struct RecordObject *self);
unsigned int RecordObjectPermissions(const struct RecordObject *self);
uintmax_t RecordObjectUid(const struct RecordObject *self);
uintmax_t RecordObjectGid(const struct RecordObject *self);
intmax_t RecordObjectSize(const struct RecordObject *self);
intmax_t RecordObjectTime(const struct RecordObject *self);
const char *RecordObjectPath(const struct RecordObject *self);
const char *RecordObjectTarget(const struct RecordObject *self);
uintmax_t RecordObjectFingerPrint(const struct RecordObject *self);
/* Free self and all owned resources. Does nothing if self is NULL. */
void RecordObjectRelease(struct RecordObject *self);
#endif