Commit f0fbfc6c f0fbfc6c32b1177f2a30ef7e37b3a6aa6edd00ce by Sean 'Shaleh' Perry

removed my readline.{c,h}

made imap use getline
1 parent f68a0e24
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifndef COUNT
#define COUNT 128 /* safe, middle of the road value */
#endif
/**
* reads a single line from *stream
* max line length is max size of size_t
*
* PRE: stream is an open FILE stream
* POST: returns an allocated string containing the line read, or errno is set
*
* note, user must free the returned string
**/
char *read_a_line(FILE *stream) {
char *line = NULL;
size_t buffsize = 0; /* counter of alloc'ed space */
if( feof(stream) ) { /* sent a bum stream */
errno = EINVAL;
return NULL;
}
do {
if ((line = realloc(line, buffsize + (sizeof(char) * COUNT))) == NULL) {
errno = ENOMEM;
return NULL;
}
if( fgets(line + (buffsize ? buffsize - 1 : 0),COUNT,stream) == NULL ) {
if( buffsize == 0 ) {
errno = EINVAL;
return NULL; /* eof w/ nothing read */
}
break; /* read a line w/o a newline char */
}
buffsize += COUNT;
} while( (strchr(line, '\n')) == NULL );
return line;
}
#ifndef _mailutils_read_a_line__
#define _mailutils_read_a_line__
char* read_a_line(FILE *stream);
#endif
......@@ -8,7 +8,6 @@
#include "imap.h"
#include "imap_commands.h"
#include "command.h"
#include "readline.h"
static void init(void);
static int mainloop(void);
......@@ -71,11 +70,12 @@ static void greeting(void) {
static int mainloop(void) {
char *client_string;
char *client_string = NULL;
size_t len = 0;
Command *command;
STATUS status;
while( (client_string = read_a_line(input)) != NULL ) {
while( getline(&client_string, &len, input) != -1 ) {
command = parse_command(client_string);
status = action(command);
......@@ -83,11 +83,11 @@ static int mainloop(void) {
command->cmd, status_code[status]);
free_command(command);
free(client_string);
if( state == LOGOUT ) /* all done, let's go */
break;
}
free(client_string);
return 1;
}
......
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifndef COUNT
#define COUNT 128 /* safe, middle of the road value */
#endif
/**
* reads a single line from *stream
* max line length is max size of size_t
*
* PRE: stream is an open FILE stream
* POST: returns an allocated string containing the line read, or errno is set
*
* note, user must free the returned string
**/
char *read_a_line(FILE *stream) {
char *line = NULL;
size_t buffsize = 0; /* counter of alloc'ed space */
if( feof(stream) ) { /* sent a bum stream */
errno = EINVAL;
return NULL;
}
do {
if ((line = realloc(line, buffsize + (sizeof(char) * COUNT))) == NULL) {
errno = ENOMEM;
return NULL;
}
if( fgets(line + (buffsize ? buffsize - 1 : 0),COUNT,stream) == NULL ) {
if( buffsize == 0 ) {
errno = EINVAL;
return NULL; /* eof w/ nothing read */
}
break; /* read a line w/o a newline char */
}
buffsize += COUNT;
} while( (strchr(line, '\n')) == NULL );
return line;
}
#ifndef _MY_read_a_line__
#define _MY_read_a_line__
char* read_a_line(FILE *stream);
#endif