Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
John McEleney
/
mailutils
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
Commit
7962bf1b
...
7962bf1bd7451aaf568cda35aaa18d5c2f4dd1c2
authored
1999-10-08 01:30:25 +0000
by
Sean 'Shaleh' Perry
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
readline routine added
1 parent
195ed11f
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
55 additions
and
0 deletions
ChangeLog
examples/readline.c
examples/readline.h
ChangeLog
View file @
7962bf1
Sean 'Shaleh' Perry <shaleh@debian.org> Thu, 7 Oct 1999 18:31:57 -0700
* included my read_a_line() in examples/
Sean 'Shaleh' Perry <shaleh@debian.org> Wed, 6 Oct 1999 13:55:42 -0700
* Cleanup some compilation issues
...
...
examples/readline.c
0 → 100644
View file @
7962bf1
#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
;
}
examples/readline.h
0 → 100644
View file @
7962bf1
#ifndef _mailutils_read_a_line__
#define _mailutils_read_a_line__
char
*
read_a_line
(
FILE
*
stream
);
#endif
Please
register
or
sign in
to post a comment