add agetline, separate estrtod to util

Signed-off-by: Hiltjo Posthuma <hiltjo@codemadness.org>
This commit is contained in:
Hiltjo Posthuma 2014-06-01 13:57:22 +02:00 committed by sin
parent daad071b31
commit d12e953f18
6 changed files with 41 additions and 20 deletions

View File

@ -7,12 +7,14 @@ HDR = crypt.h fs.h text.h md5.h sha1.h sha256.h sha512.h util.h arg.h
LIB = \
util/afgets.o \
util/agetcwd.o \
util/agetline.o \
util/apathmax.o \
util/concat.o \
util/cp.o \
util/crypt.o \
util/enmasse.o \
util/eprintf.o \
util/estrtod.o \
util/estrtol.o \
util/fnck.o \
util/getlines.o \

20
seq.c
View File

@ -8,7 +8,6 @@
static int digitsleft(const char *);
static int digitsright(const char *);
static double estrtod(const char *);
static bool validfmt(const char *);
static void
@ -89,7 +88,7 @@ main(int argc, char *argv[])
return EXIT_SUCCESS;
}
int
static int
digitsleft(const char *d)
{
char *exp;
@ -103,7 +102,7 @@ digitsleft(const char *d)
return MAX(0, strspn(d, "-0123456789") + shift);
}
int
static int
digitsright(const char *d)
{
char *exp;
@ -116,19 +115,7 @@ digitsright(const char *d)
return MAX(0, after - shift);
}
double
estrtod(const char *s)
{
char *end;
double d;
d = strtod(s, &end);
if(end == s || *end != '\0')
eprintf("%s: not a real number\n", s);
return d;
}
bool
static bool
validfmt(const char *fmt)
{
int occur = 0;
@ -164,4 +151,3 @@ format:
return false;
}
}

1
text.h
View File

@ -9,4 +9,5 @@ struct linebuf {
void getlines(FILE *, struct linebuf *);
char *afgets(char **, size_t *, FILE *);
ssize_t agetline(char **, size_t *, FILE *);
void concat(FILE *, const char *, FILE *, const char *);

1
util.h
View File

@ -17,6 +17,7 @@ void apathmax(char **, long *);
void enmasse(int, char **, int (*)(const char *, const char *));
void eprintf(const char *, ...);
void enprintf(int, const char *, ...);
double estrtod(const char *);
long estrtol(const char *, int);
void fnck(const char *, const char *, int (*)(const char *, const char *));
void putword(const char *);

13
util/agetline.c Normal file
View File

@ -0,0 +1,13 @@
/* See LICENSE file for copyright and license details. */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "../text.h"
#include "../util.h"
ssize_t
agetline(char **p, size_t *size, FILE *fp)
{
return getline(p, size, fp);
}

18
util/estrtod.c Normal file
View File

@ -0,0 +1,18 @@
/* See LICENSE file for copyright and license details. */
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include "../util.h"
double
estrtod(const char *s)
{
char *end;
double d;
d = strtod(s, &end);
if(end == s || *end != '\0')
eprintf("%s: not a real number\n", s);
return d;
}