diff options
author | Brian Cully <bjc@kublai.com> | 2008-03-02 11:44:52 -0500 |
---|---|---|
committer | Brian Cully <github.20.shmit@spamgourmet.com> | 2008-03-02 11:44:52 -0500 |
commit | 4c31a79f1f76b6d80fffd05180dadcbb5a882293 (patch) | |
tree | 4452bb96e63748f0db3074f4f7f65bb8c19ed644 /src/mysqlerl.c | |
parent | 26858b9722eb539cdb6fa762cb15071cfe753f45 (diff) | |
download | mysqlerl-4c31a79f1f76b6d80fffd05180dadcbb5a882293.tar.gz mysqlerl-4c31a79f1f76b6d80fffd05180dadcbb5a882293.zip |
Move logger/io routines to separate modules.
Diffstat (limited to 'src/mysqlerl.c')
-rw-r--r-- | src/mysqlerl.c | 87 |
1 files changed, 3 insertions, 84 deletions
diff --git a/src/mysqlerl.c b/src/mysqlerl.c index 9266baa..b0bbc87 100644 --- a/src/mysqlerl.c +++ b/src/mysqlerl.c @@ -4,20 +4,16 @@ * Copyright (C) 2008, Brian Cully <bjc@kublai.com> */ +#include "io.h" +#include "log.h" + #include <erl_interface.h> #include <ei.h> #include <mysql.h> #include <errno.h> -#include <stdio.h> -#include <stdarg.h> #include <stdlib.h> #include <string.h> -#include <sys/types.h> -#include <unistd.h> - -const char *LOGPATH = "/tmp/mysqlerl.log"; -static FILE *logfile = NULL; const char *QUERY_MSG = "sql_query"; @@ -29,83 +25,6 @@ struct msg { }; typedef struct msg msg_t; -void -openlog() -{ - logfile = fopen(LOGPATH, "a"); -} - -void -closelog() -{ - fclose(logfile); -} - -void -logmsg(const char *format, ...) -{ - FILE *out = logfile; - va_list args; - - if (logfile == NULL) - out = stderr; - - va_start(args, format); - (void)vfprintf(out, format, args); - (void)fprintf(out, "\n"); - va_end(args); - - fflush(out); -} - -int -restartable_read(unsigned char *buf, size_t buflen) -{ - ssize_t rc, readb; - - rc = 0; - READLOOP: - while (rc < buflen) { - readb = read(STDIN_FILENO, buf + rc, buflen - rc); - if (readb == -1) { - if (errno == EAGAIN || errno == EINTR) - goto READLOOP; - - return -1; - } else if (readb == 0) { - logmsg("ERROR: EOF trying to read additional %d bytes from " - "standard input", buflen - rc); - return -1; - } - - rc += readb; - } - - return rc; -} - -int -restartable_write(const unsigned char *buf, size_t buflen) -{ - ssize_t rc, wroteb; - - rc = 0; - WRITELOOP: - while (rc < buflen) { - wroteb = write(STDOUT_FILENO, buf + rc, buflen - rc); - if (wroteb == -1) { - if (errno == EAGAIN || errno == EINTR) - goto WRITELOOP; - - return -1; - } - - rc += wroteb; - } - - return rc; -} - msg_t * read_msg() { |