ref: f95ddbe45db70bf58be577607142ba9fa5a77843
parent: 4beba07146b277c8ca169c82e387687f6f8d0645
author: cancel <cancel@cancel.fm>
date: Mon Jan 6 21:57:55 EST 2020
Fix up more prefs reading code
--- a/prefs.c
+++ b/prefs.c
@@ -3,12 +3,10 @@
ORCA_FORCE_NO_INLINE
Readprefs_result prefs_read_line(FILE* file, char* buf, Usz bufsize,
- Usz* out_strlen, char** out_left,
- Usz* out_leftsize, char** out_right,
- Usz* out_rightsize) {
+ char** out_left, Usz* out_leftsize,
+ char** out_right, Usz* out_rightsize) {
Usz len, a0, a1, b0, b1;
char* s;
- *out_strlen = 0;
if (bufsize < 2)
goto insufficient_buffer;
#if SIZE_MAX > INT_MAX
@@ -24,7 +22,6 @@
len = strlen(buf);
if (len == bufsize - 1 && buf[len - 1] != '\n' && !feof(file))
goto insufficient_buffer;
- *out_strlen = len - 1;
a0 = 0; // start of left
for (;;) {
if (a0 == len)
@@ -90,13 +87,17 @@
ioerror:
err = Readprefs_io_error;
goto fail;
-ignore:
- s[len - 1] = '\0';
- err = Readprefs_irrelevant;
- goto fail;
fail:
*out_left = NULL;
*out_leftsize = 0;
+ goto no_right;
+ignore:
+ s[len - 1] = '\0';
+ *out_left = s;
+ *out_leftsize = len;
+ err = Readprefs_irrelevant;
+ goto no_right;
+no_right:
*out_right = NULL;
*out_rightsize = 0;
return err;
--- a/prefs.h
+++ b/prefs.h
@@ -3,14 +3,13 @@
#include <stdio.h> // FILE cannot be forward declared
typedef enum {
- Readprefs_left_and_right = 0,
- Readprefs_irrelevant,
- Readprefs_buffer_too_small,
- Readprefs_eof,
- Readprefs_io_error,
+ Readprefs_left_and_right = 0, // left and right will be set
+ Readprefs_irrelevant, // only left will be set
+ Readprefs_buffer_too_small, // neither will be set
+ Readprefs_eof, // "
+ Readprefs_io_error, // "
} Readprefs_result;
Readprefs_result prefs_read_line(FILE* file, char* buf, Usz bufsize,
- Usz* out_linelen, char** out_left,
- Usz* out_leftlen, char** out_right,
- Usz* out_rightlen);
+ char** out_left, Usz* out_leftlen,
+ char** out_right, Usz* out_rightlen);