|
@@ -217,18 +217,20 @@ static char *faux_file_takeaway_rest(faux_file_t *f) {
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
+
|
|
|
*
|
|
|
- * Gets line (data ends with EOL) from internal buffer as a single C-string
|
|
|
- * (i.e. ends with '\0'). The resulting line will not contain trailing EOL but
|
|
|
- * EOL will be removed from internal buffer together with line.
|
|
|
+ * Universal function for faux_file_takeaway(), faux_file_takeway_raw()
|
|
|
+ * implementation.
|
|
|
*
|
|
|
* @warning Returned pointer must be freed by faux_str_free() later.
|
|
|
*
|
|
|
* @param [in] f File object.
|
|
|
+ * @param [in] raw Boolean flag.
|
|
|
+ * BOOL_TRUE - include trailing EOL to resulting string,
|
|
|
+ * BOOL_FALSE - don't include
|
|
|
* @return Allocated string (with trailing '\0') with line.
|
|
|
*/
|
|
|
-static char *faux_file_takeaway_line(faux_file_t *f) {
|
|
|
+static char *faux_file_takeaway_line_internal(faux_file_t *f, bool_t raw) {
|
|
|
|
|
|
char *find = NULL;
|
|
|
const char *eol = "\n\r";
|
|
@@ -244,8 +246,46 @@ static char *faux_file_takeaway_line(faux_file_t *f) {
|
|
|
return NULL;
|
|
|
line_len = find - f->buf;
|
|
|
|
|
|
-
|
|
|
- return faux_file_takeaway(f, line_len, 1);
|
|
|
+ if (raw) {
|
|
|
+
|
|
|
+ return faux_file_takeaway(f, line_len + 1, 0);
|
|
|
+ } else {
|
|
|
+
|
|
|
+ return faux_file_takeaway(f, line_len, 1);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ *
|
|
|
+ * Gets line (data ends with EOL) from internal buffer as a single C-string
|
|
|
+ * (i.e. ends with '\0'). The resulting line will contain trailing EOL.
|
|
|
+ *
|
|
|
+ * @warning Returned pointer must be freed by faux_str_free() later.
|
|
|
+ *
|
|
|
+ * @param [in] f File object.
|
|
|
+ * @return Allocated string (with trailing '\0') with line.
|
|
|
+ */
|
|
|
+static char *faux_file_takeaway_line_raw(faux_file_t *f) {
|
|
|
+
|
|
|
+ return faux_file_takeaway_line_internal(f, BOOL_TRUE);
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ *
|
|
|
+ * Gets line (data ends with EOL) from internal buffer as a single C-string
|
|
|
+ * (i.e. ends with '\0'). The resulting line will not contain trailing EOL but
|
|
|
+ * EOL will be removed from internal buffer together with line.
|
|
|
+ *
|
|
|
+ * @warning Returned pointer must be freed by faux_str_free() later.
|
|
|
+ *
|
|
|
+ * @param [in] f File object.
|
|
|
+ * @return Allocated string (with trailing '\0') with line.
|
|
|
+ */
|
|
|
+static char *faux_file_takeaway_line(faux_file_t *f) {
|
|
|
+
|
|
|
+ return faux_file_takeaway_line_internal(f, BOOL_FALSE);
|
|
|
}
|
|
|
|
|
|
|
|
@@ -280,18 +320,19 @@ static int faux_file_enlarge_buffer(faux_file_t *f) {
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
+
|
|
|
*
|
|
|
- * Actually function searches for line within internal buffer. If line is not
|
|
|
- * found then function reads new data from file and searches for the line again.
|
|
|
- * The last line in file (without trailing EOL) is considered as line too.
|
|
|
+ * Function for implementation faux_file_getline_raw() and faux_file_getline().
|
|
|
*
|
|
|
* @warning Returned pointer must be freed by faux_str_free() later.
|
|
|
*
|
|
|
* @param [in] f File object.
|
|
|
+ * @param [in] raw
|
|
|
+ * BOOL_TRUE - raw mode (with trailing EOL)
|
|
|
+ * BOOL_FALSE - without trailing EOL
|
|
|
* @return Line pointer or NULL on error.
|
|
|
*/
|
|
|
-char *faux_file_getline(faux_file_t *f) {
|
|
|
+char *faux_file_getline_internal(faux_file_t *f, bool_t raw) {
|
|
|
|
|
|
ssize_t bytes_readed = 0;
|
|
|
|
|
@@ -303,7 +344,11 @@ char *faux_file_getline(faux_file_t *f) {
|
|
|
char *find = NULL;
|
|
|
|
|
|
|
|
|
- find = faux_file_takeaway_line(f);
|
|
|
+ if (raw) {
|
|
|
+ find = faux_file_takeaway_line_raw(f);
|
|
|
+ } else {
|
|
|
+ find = faux_file_takeaway_line(f);
|
|
|
+ }
|
|
|
if (find)
|
|
|
return find;
|
|
|
|
|
@@ -329,6 +374,41 @@ char *faux_file_getline(faux_file_t *f) {
|
|
|
return faux_file_takeaway_rest(f);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ *
|
|
|
+ * Raw line is a line with trailing EOL included.
|
|
|
+ * Actually function searches for line within internal buffer. If line is not
|
|
|
+ * found then function reads new data from file and searches for the line again.
|
|
|
+ * The last line in file (without trailing EOL) is considered as line too.
|
|
|
+ *
|
|
|
+ * @warning Returned pointer must be freed by faux_str_free() later.
|
|
|
+ *
|
|
|
+ * @param [in] f File object.
|
|
|
+ * @return Line pointer or NULL on error.
|
|
|
+ */
|
|
|
+char *faux_file_getline_raw(faux_file_t *f) {
|
|
|
+
|
|
|
+ return faux_file_getline_internal(f, BOOL_TRUE);
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ *
|
|
|
+ * Actually function searches for line within internal buffer. If line is not
|
|
|
+ * found then function reads new data from file and searches for the line again.
|
|
|
+ * The last line in file (without trailing EOL) is considered as line too.
|
|
|
+ *
|
|
|
+ * @warning Returned pointer must be freed by faux_str_free() later.
|
|
|
+ *
|
|
|
+ * @param [in] f File object.
|
|
|
+ * @return Line pointer or NULL on error.
|
|
|
+ */
|
|
|
+char *faux_file_getline(faux_file_t *f) {
|
|
|
+
|
|
|
+ return faux_file_getline_internal(f, BOOL_FALSE);
|
|
|
+}
|
|
|
+
|
|
|
|
|
|
|
|
|
*
|