Apply RecordObject namespace to all methods

This commit is contained in:
Fabio Scotto di Santolo
2026-08-25 23:45:56 +02:00
parent 53e13e9c51
commit ad062794d8
5 changed files with 46 additions and 40 deletions

View File

@@ -25,18 +25,18 @@ struct RecordObject;
// Methods // Methods
struct RecordObject *NewRecordObject(); struct RecordObject *NewRecordObject();
int Unpack(struct RecordObject *, char *); int RecordObjectUnpack(struct RecordObject *, char *);
int RecordObjectWrite(struct RecordObject *self, const char *path, FILE *out); int RecordObjectWrite(struct RecordObject *self, const char *path, FILE *out);
int Compare(struct RecordObject *, struct RecordObject *); int RecordObjectCompare(struct RecordObject *, struct RecordObject *);
char GetFileType(const struct RecordObject *); char RecordObjectFileType(const struct RecordObject *);
unsigned int GetPermissions(const struct RecordObject *); unsigned int RecordObjectPermissions(const struct RecordObject *);
uintmax_t GetUid(const struct RecordObject *); uintmax_t RecordObjectUid(const struct RecordObject *);
uintmax_t GetGid(const struct RecordObject *); uintmax_t RecordObjectGid(const struct RecordObject *);
intmax_t GetSize(const struct RecordObject *); intmax_t RecordObjectSize(const struct RecordObject *);
intmax_t GetTime(const struct RecordObject *); intmax_t RecordObjectTime(const struct RecordObject *);
const char *GetPath(const struct RecordObject *); const char *RecordObjectPath(const struct RecordObject *);
const char *GetTarget(const struct RecordObject *); const char *RecordObjectTarget(const struct RecordObject *);
uintmax_t GetFingerPrint(const struct RecordObject *); uintmax_t RecordObjectFingerPrint(const struct RecordObject *);
int Release(struct RecordObject *); int RecordObjectRelease(struct RecordObject *);
#endif #endif

View File

@@ -25,7 +25,7 @@ static int write_record(const char *path, void *context) {
if (r == NULL) if (r == NULL)
return -1; return -1;
int ret = RecordObjectWrite(r, path, (FILE *)context); int ret = RecordObjectWrite(r, path, (FILE *)context);
Release(r); RecordObjectRelease(r);
return ret < 0 ? -1 : 0; return ret < 0 ? -1 : 0;
} }

View File

@@ -37,10 +37,10 @@ static int load_in_memory(const char *file, struct RecordObject ***records,
goto failure; goto failure;
} }
int ret = Unpack(objp, buf); int ret = RecordObjectUnpack(objp, buf);
if (ret == -1) { if (ret == -1) {
errno = EINVAL; errno = EINVAL;
Release(objp); RecordObjectRelease(objp);
goto failure; goto failure;
} }
@@ -70,7 +70,7 @@ failure:
static int dealloc(struct RecordObject **records, int size) { static int dealloc(struct RecordObject **records, int size) {
for (int j = 0; j < size; j++) { for (int j = 0; j < size; j++) {
Release(records[j]); RecordObjectRelease(records[j]);
records[j] = NULL; records[j] = NULL;
} }
free(records); free(records);
@@ -80,7 +80,7 @@ static int dealloc(struct RecordObject **records, int size) {
static int order_by_path(const void *o1, const void *o2) { static int order_by_path(const void *o1, const void *o2) {
const struct RecordObject *r1 = *(const struct RecordObject *const *)o1; const struct RecordObject *r1 = *(const struct RecordObject *const *)o1;
const struct RecordObject *r2 = *(const struct RecordObject *const *)o2; const struct RecordObject *r2 = *(const struct RecordObject *const *)o2;
return strcmp(GetPath(r1), GetPath(r2)); return strcmp(RecordObjectPath(r1), RecordObjectPath(r2));
} }
int diff(const char *file1, const char *file2) { int diff(const char *file1, const char *file2) {
@@ -116,16 +116,16 @@ int diff(const char *file1, const char *file2) {
char code = 0; char code = 0;
const char *path = NULL; const char *path = NULL;
int c = strcmp(GetPath(r1), GetPath(r2)); int c = strcmp(RecordObjectPath(r1), RecordObjectPath(r2));
if (c < 0) { if (c < 0) {
code = 'D'; code = 'D';
path = GetPath(r1); path = RecordObjectPath(r1);
m++; m++;
} else if (c > 0) { } else if (c > 0) {
code = 'A'; code = 'A';
path = GetPath(r2); path = RecordObjectPath(r2);
n++; n++;
} else if (Compare(r1, r2) != 0) { } else if (RecordObjectCompare(r1, r2) != 0) {
switch (field) { switch (field) {
case TARGET: case TARGET:
code = 'L'; code = 'L';
@@ -137,7 +137,7 @@ int diff(const char *file1, const char *file2) {
code = 'M'; code = 'M';
break; break;
} }
path = GetPath(r1); path = RecordObjectPath(r1);
m++; m++;
n++; n++;
} else { } else {
@@ -152,13 +152,13 @@ int diff(const char *file1, const char *file2) {
while (m < len1) { while (m < len1) {
const struct RecordObject *r = records1[m]; const struct RecordObject *r = records1[m];
fprintf(stdout, "D\t%s\n", GetPath(r)); fprintf(stdout, "D\t%s\n", RecordObjectPath(r));
m++; m++;
} }
while (n < len2) { while (n < len2) {
const struct RecordObject *r = records2[n]; const struct RecordObject *r = records2[n];
fprintf(stdout, "A\t%s\n", GetPath(r)); fprintf(stdout, "A\t%s\n", RecordObjectPath(r));
n++; n++;
} }

View File

@@ -38,17 +38,17 @@ int list(const char *snapshot) {
rc = -1; rc = -1;
goto out; goto out;
} }
int ret = Unpack(objp, buf); int ret = RecordObjectUnpack(objp, buf);
if (field != NONE) { if (field != NONE) {
fprintf(stderr, "%s:%d: invalid %s\n", snapshot, i + 1, FieldName(field)); fprintf(stderr, "%s:%d: invalid %s\n", snapshot, i + 1, FieldName(field));
rc = 128; rc = 128;
Release(objp); RecordObjectRelease(objp);
break; break;
} }
if (ret == -1) { if (ret == -1) {
fprintf(stderr, "%s:%d: unparsable line\n", snapshot, i + 1); fprintf(stderr, "%s:%d: unparsable line\n", snapshot, i + 1);
Release(objp); RecordObjectRelease(objp);
rc = 128; rc = 128;
break; break;
} }
@@ -74,7 +74,7 @@ out:;
free(buf); free(buf);
if (records != NULL) { if (records != NULL) {
for (int j = 0; j < arr_size; j++) { for (int j = 0; j < arr_size; j++) {
Release(records[j]); RecordObjectRelease(records[j]);
records[j] = NULL; records[j] = NULL;
} }
free(records); free(records);

View File

@@ -255,7 +255,7 @@ struct RecordObject *NewRecordObject() {
return ret; return ret;
} }
int Unpack(struct RecordObject *self, char *s) { int RecordObjectUnpack(struct RecordObject *self, char *s) {
char *fields[NFIELDS]; char *fields[NFIELDS];
if (split_record(s, fields, '|') == -1) if (split_record(s, fields, '|') == -1)
return -1; return -1;
@@ -329,7 +329,7 @@ int Unpack(struct RecordObject *self, char *s) {
return 0; return 0;
} }
int Compare(struct RecordObject *self, struct RecordObject *other) { int RecordObjectCompare(struct RecordObject *self, struct RecordObject *other) {
field = NONE; field = NONE;
if (self == NULL) if (self == NULL)
@@ -433,7 +433,7 @@ int RecordObjectWrite(struct RecordObject *self, const char *path, FILE *out) {
self->path); self->path);
} }
int Release(struct RecordObject *self) { int RecordObjectRelease(struct RecordObject *self) {
if (self == NULL) if (self == NULL)
return -1; return -1;
if (self->path != NULL) { if (self->path != NULL) {
@@ -449,16 +449,22 @@ int Release(struct RecordObject *self) {
} }
// Accessors // Accessors
char GetFileType(const struct RecordObject *self) { return self->file_type; } char RecordObjectFileType(const struct RecordObject *self) {
unsigned int GetPermissions(const struct RecordObject *self) { return self->file_type;
}
unsigned int RecordObjectPermissions(const struct RecordObject *self) {
return self->perm; return self->perm;
} }
uintmax_t GetUid(const struct RecordObject *self) { return self->uid; } uintmax_t RecordObjectUid(const struct RecordObject *self) { return self->uid; }
uintmax_t GetGid(const struct RecordObject *self) { return self->gid; } uintmax_t RecordObjectGid(const struct RecordObject *self) { return self->gid; }
intmax_t GetSize(const struct RecordObject *self) { return self->size; } intmax_t RecordObjectSize(const struct RecordObject *self) { return self->size; }
intmax_t GetTime(const struct RecordObject *self) { return self->time; } intmax_t RecordObjectTime(const struct RecordObject *self) { return self->time; }
const char *GetPath(const struct RecordObject *self) { return self->path; } const char *RecordObjectPath(const struct RecordObject *self) {
const char *GetTarget(const struct RecordObject *self) { return self->target; } return self->path;
uintmax_t GetFingerPrint(const struct RecordObject *self) { }
const char *RecordObjectTarget(const struct RecordObject *self) {
return self->target;
}
uintmax_t RecordObjectFingerPrint(const struct RecordObject *self) {
return self->fingerprint; return self->fingerprint;
} }