memcmp-hack.patch
text/x-diff
Filename: memcmp-hack.patch
Type: text/x-diff
Part: 1
Patch
Same data as JSON:
GET /api/v1/attachments/:id/patch
the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes.
API reference →
Format: unified
| File | + | − |
|---|---|---|
| src/include/port.h | 11 | 0 |
| src/port/snprintf.c | 37 | 0 |
diff --git a/src/include/port.h b/src/include/port.h
index e654d5c..e5eda63 100644
--- a/src/include/port.h
+++ b/src/include/port.h
@@ -196,6 +196,17 @@ extern char *pg_strerror_r(int errnum, char *buf, size_t buflen);
#define strerror_r pg_strerror_r
#define PG_STRERROR_R_BUFLEN 256 /* Recommended buffer size for strerror_r */
+/* Override these too for sort testing */
+extern int pg_memcmp(const void *s1, const void *s2, size_t n);
+extern int pg_strcmp(const char *s1, const char *s2);
+extern int pg_strncmp(const char *s1, const char *s2, size_t n);
+#undef memcmp
+#undef strcmp
+#undef strncmp
+#define memcmp pg_memcmp
+#define strcmp pg_strcmp
+#define strncmp pg_strncmp
+
/* Portable prompt handling */
extern void simple_prompt(const char *prompt, char *destination, size_t destlen,
bool echo);
diff --git a/src/port/snprintf.c b/src/port/snprintf.c
index ef496fa..be404b1 100644
--- a/src/port/snprintf.c
+++ b/src/port/snprintf.c
@@ -1357,3 +1357,40 @@ trailing_pad(int padlen, PrintfTarget *target)
if (padlen < 0)
dopr_outchmulti(' ', -padlen, target);
}
+
+#undef memcmp
+#undef strcmp
+#undef strncmp
+
+int pg_memcmp(const void *s1, const void *s2, size_t n)
+{
+ int res = memcmp(s1, s2, n);
+
+ if (res < 0)
+ return INT_MIN;
+ if (res > 0)
+ return INT_MAX;
+ return 0;
+}
+
+int pg_strcmp(const char *s1, const char *s2)
+{
+ int res = strcmp(s1, s2);
+
+ if (res < 0)
+ return INT_MIN;
+ if (res > 0)
+ return INT_MAX;
+ return 0;
+}
+
+int pg_strncmp(const char *s1, const char *s2, size_t n)
+{
+ int res = strncmp(s1, s2, n);
+
+ if (res < 0)
+ return INT_MIN;
+ if (res > 0)
+ return INT_MAX;
+ return 0;
+}