[or-cvs] shift read_file_to_str() into util.c
Roger Dingledine
arma at seul.org
Sun Sep 28 06:48:32 UTC 2003
Update of /home/or/cvsroot/src/common
In directory moria.mit.edu:/home2/arma/work/onion/cvs/src/common
Modified Files:
tortls.c tortls.h util.c util.h
Log Message:
shift read_file_to_str() into util.c
Index: tortls.c
===================================================================
RCS file: /home/or/cvsroot/src/common/tortls.c,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- tortls.c 27 Sep 2003 20:07:40 -0000 1.17
+++ tortls.c 28 Sep 2003 06:47:29 -0000 1.18
@@ -78,6 +78,7 @@
case SSL_ERROR_SYSCALL:
if (extra&CATCH_SYSCALL)
return _TOR_TLS_SYSCALL;
+ assert(severity != LOG_ERR); /* XXX remove me when the bug is found */
log(severity, "TLS error: <syscall error>.");
return TOR_TLS_ERROR;
case SSL_ERROR_ZERO_RETURN:
@@ -485,7 +486,7 @@
}
int
-tor_tls_get_pending_bytees(tor_tls *tls)
+tor_tls_get_pending_bytes(tor_tls *tls)
{
assert(tls);
return SSL_pending(tls->ssl);
Index: tortls.h
===================================================================
RCS file: /home/or/cvsroot/src/common/tortls.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- tortls.h 27 Sep 2003 20:07:40 -0000 1.7
+++ tortls.h 28 Sep 2003 06:47:29 -0000 1.8
@@ -26,6 +26,6 @@
int tor_tls_write(tor_tls *tls, char *cp, int n);
int tor_tls_handshake(tor_tls *tls);
int tor_tls_shutdown(tor_tls *tls);
-int tor_tls_get_pending_bytees(tor_tls *tls);
+int tor_tls_get_pending_bytes(tor_tls *tls);
#endif
Index: util.c
===================================================================
RCS file: /home/or/cvsroot/src/common/util.c,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -d -r1.20 -r1.21
--- util.c 26 Sep 2003 22:27:22 -0000 1.20
+++ util.c 28 Sep 2003 06:47:29 -0000 1.21
@@ -101,7 +101,7 @@
*/
/* a wrapper for write(2) that makes sure to write all count bytes.
- * Only use if fd is a blocking socket. */
+ * Only use if fd is a blocking fd. */
int write_all(int fd, const void *buf, size_t count) {
int written = 0;
int result;
@@ -116,7 +116,7 @@
}
/* a wrapper for read(2) that makes sure to read all count bytes.
- * Only use if fd is a blocking socket. */
+ * Only use if fd is a blocking fd. */
int read_all(int fd, void *buf, size_t count) {
int numread = 0;
int result;
@@ -391,3 +391,42 @@
}
return 0;
}
+
+char *read_file_to_str(const char *filename) {
+ int fd; /* router file */
+ struct stat statbuf;
+ char *string;
+
+ assert(filename);
+
+ if(strcspn(filename,CONFIG_LEGAL_FILENAME_CHARACTERS) != 0) {
+ log_fn(LOG_WARNING,"Filename %s contains illegal characters.",filename);
+ return NULL;
+ }
+
+ if(stat(filename, &statbuf) < 0) {
+ log_fn(LOG_WARNING,"Could not stat %s.",filename);
+ return NULL;
+ }
+
+ fd = open(filename,O_RDONLY,0);
+ if (fd<0) {
+ log_fn(LOG_WARNING,"Could not open %s.",filename);
+ return NULL;
+ }
+
+ string = tor_malloc(statbuf.st_size+1);
+
+ if(read_all(fd,string,statbuf.st_size) != statbuf.st_size) {
+ log_fn(LOG_WARNING,"Couldn't read all %ld bytes of file '%s'.",
+ (long)statbuf.st_size,filename);
+ free(string);
+ close(fd);
+ return NULL;
+ }
+ close(fd);
+
+ string[statbuf.st_size] = 0; /* null terminate it */
+ return string;
+}
+
Index: util.h
===================================================================
RCS file: /home/or/cvsroot/src/common/util.h,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- util.h 26 Sep 2003 18:27:34 -0000 1.12
+++ util.h 28 Sep 2003 06:47:29 -0000 1.13
@@ -67,6 +67,7 @@
*/
int check_private_dir(const char *dirname, int create);
int write_str_to_file(const char *fname, const char *str);
+char *read_file_to_str(const char *filename);
/* Minimalist interface to run a void function in the background. On
unix calls fork, on win32 calls beginthread. Returns -1 on failure.
More information about the tor-commits
mailing list