diff rvinterf/etmsync/fswrite.c @ 306:8136fb5eb292

fc-fsio: write_buf_to_file() function made global in prep for upload-rf-table
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 21 Nov 2017 06:09:35 +0000
parents e7502631a0f9
children a0754c98fc2b
line wrap: on
line diff
--- a/rvinterf/etmsync/fswrite.c	Mon Nov 20 17:51:23 2017 +0000
+++ b/rvinterf/etmsync/fswrite.c	Tue Nov 21 06:09:35 2017 +0000
@@ -161,3 +161,29 @@
 		return(ERROR_USAGE);
 	}
 }
+
+write_buf_to_file(pathname, data, datalen)
+	char *pathname;
+	u_char *data;
+{
+	int tfd, rc, chunk, remain;
+
+	if (datalen <= max_short_file_write(pathname))
+		return do_short_fwrite(pathname, data, datalen);
+	/* do it the long way */
+	rc = fd_open(pathname, FFS_O_WRONLY | FFS_O_CREATE | FFS_O_TRUNC, &tfd);
+	if (rc)
+		return(rc);
+	for (remain = datalen; remain; remain -= chunk) {
+		chunk = remain;
+		if (chunk > 240)
+			chunk = 240;
+		rc = fd_write(tfd, data, chunk);
+		if (rc) {
+			fd_close(tfd);
+			return(rc);
+		}
+		data += chunk;
+	}
+	return fd_close(tfd);
+}