commit 41ae6bfe56c7b53b2340323fd3012d3e83749396
parent a52993c53227570d7c6f5d5c78eabf50310cfd9d
Author: Anselm R. Garbe <garbeam@wmii.de>
Date: Mon, 29 May 2006 11:36:59 +0200
removed strtonum interface, using strtol+errno instead
Diffstat:
8 files changed, 34 insertions(+), 101 deletions(-)
diff --git a/cmd/wm/area.c b/cmd/wm/area.c
@@ -5,6 +5,7 @@
#include <stdlib.h>
#include <string.h>
+#include <errno.h>
#include "wm.h"
@@ -123,9 +124,8 @@ select_area(Area *a, char *arg)
return;
}
else {
- const char *errstr;
- i = cext_strtonum(arg, 0, v->area.size - 1, &errstr);
- if(errstr)
+ i = strtol(arg, nil, 10);
+ if(errno)
return;
}
new = v->area.data[i];
diff --git a/cmd/wm/client.c b/cmd/wm/client.c
@@ -5,6 +5,7 @@
#include <stdlib.h>
#include <string.h>
+#include <errno.h>
#include <X11/Xatom.h>
#include "wm.h"
@@ -615,9 +616,8 @@ select_client(Client *c, char *arg)
i = 0;
}
else {
- const char *errstr;
- i = cext_strtonum(arg, 0, a->frame.size - 1, &errstr);
- if(errstr)
+ i = strtol(arg, nil, 10);
+ if(errno)
return;
}
focus_client(a->frame.data[i]->client, True);
@@ -685,7 +685,6 @@ size_client(Client *c, char *arg)
void
send_client(Client *c, char *arg)
{
- const char *errstr;
Frame *f = c->frame.data[c->sel];
Area *to, *a = f->area;
View *v = a->view;
@@ -742,8 +741,8 @@ send_client(Client *c, char *arg)
focus_client(c, True);
}
else if(i) {
- j = cext_strtonum(arg, 0, v->area.size - 1, &errstr);
- if(errstr)
+ j = strtol(arg, nil, 10);
+ if(errno)
return;
to = v->area.data[j];
send_to_area(to, a, c);
diff --git a/cmd/wm/fs.c b/cmd/wm/fs.c
@@ -3,6 +3,7 @@
* See LICENSE file for license details.
*/
+#include <errno.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
@@ -325,8 +326,8 @@ type_of_name(Qid wqid[IXP_MAX_WELEM], unsigned short qsel, char *name)
return FsDview;
if(!strncmp(name, "sel", 4))
goto dyndir;
- i = (unsigned short) cext_strtonum(name, 0, 0xffff, &errstr);
- if(errstr)
+ i = (unsigned short) strtol(name, nil, 10);
+ if(errno)
return FsLast;
dyndir:
switch(dir_type) {
@@ -385,8 +386,8 @@ qid_of_name(Qid wqid[IXP_MAX_WELEM], unsigned short qsel, char *name)
new.path = pack_qpath(FsDarea, p->id, p->area.data[p->sel]->id, 0);
}
else {
- i = cext_strtonum(name, 0, 0xffff, &errstr);
- if(errstr || (i >= p->area.size))
+ i = strtol(name, nil, 10);
+ if(errno || (i >= p->area.size))
return nil;
new.path = pack_qpath(FsDarea, p->id, p->area.data[i]->id, 0);
}
@@ -405,7 +406,7 @@ qid_of_name(Qid wqid[IXP_MAX_WELEM], unsigned short qsel, char *name)
new.path = pack_qpath(FsDclient, p->id, a->id, a->frame.data[a->sel]->id);
}
else {
- i = cext_strtonum(name, 0, 0xffff, &errstr);
+ i = strtol(name, nil, 10);
if(errstr || (i >= a->frame.size))
return nil;
new.path = pack_qpath(FsDclient, p->id, a->id, a->frame.data[i]->id);
@@ -415,8 +416,8 @@ qid_of_name(Qid wqid[IXP_MAX_WELEM], unsigned short qsel, char *name)
case FsDGclient:
if(dir_type != FsDclients)
return nil;
- i = cext_strtonum(name, 0, 0xffff, &errstr);
- if(errstr || (i >= client.size))
+ i = strtol(name, nil, 10);
+ if(errno || (i >= client.size))
return nil;
new.path = pack_qpath(FsDGclient, client.data[i]->id, 0, 0);
break;
@@ -1357,8 +1358,8 @@ xwrite(IXPConn *c, Fcall *fcall)
return Ebadvalue;
memcpy(buf, fcall->data, fcall->count);
buf[fcall->count] = 0;
- i = cext_strtonum(buf, 0, 0xffff, &errstr);
- if(errstr)
+ i = strtol(buf, nil, 10);
+ if(errno)
return Ebadvalue;
def.border = i;
resize_all_clients();
@@ -1484,8 +1485,8 @@ xwrite(IXPConn *c, Fcall *fcall)
return Ebadvalue;
memcpy(buf, fcall->data, fcall->count);
buf[fcall->count] = 0;
- i = cext_strtonum(buf, 0, rect.width - MIN_COLWIDTH, &errstr);
- if(errstr || (i && i < MIN_COLWIDTH))
+ i = strtol(buf, nil, 10);
+ if(errno || (i && i < MIN_COLWIDTH))
return Ebadvalue;
def.colw = i;
break;
diff --git a/cmd/wmiiwarp.c b/cmd/wmiiwarp.c
@@ -6,10 +6,11 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
+#include <errno.h>
#include <X11/Xlib.h>
-#include "cext.h"
+#include <cext.h>
static char version[] = "wmiiwarp - " VERSION ", (C)opyright MMIV-MMV Anselm R. Garbe\n";
@@ -24,7 +25,6 @@ int
main(int argc, char **argv)
{
Display *dpy;
- const char *err;
int x, y;
/* command line args */
@@ -38,11 +38,11 @@ main(int argc, char **argv)
fprintf(stderr, "%s", "wmiiwarp: cannot open display\n");
exit(1);
}
- x = cext_strtonum(argv[1], 0, DisplayWidth(dpy, DefaultScreen(dpy)), &err);
- if(err)
+ x = strtol(argv[1], nil, 10);
+ if(errno)
usage();
- y = cext_strtonum(argv[2], 0, DisplayWidth(dpy, DefaultScreen(dpy)), &err);
- if(err)
+ y = strtol(argv[2], nil, 10);
+ if(errno)
usage();
XWarpPointer(dpy, None, RootWindow(dpy, DefaultScreen(dpy)), 0, 0, 0, 0, x, y);
XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime);
diff --git a/libcext/Makefile b/libcext/Makefile
@@ -3,7 +3,7 @@
include ../config.mk
-SRC = emallocz.c estrdup.c strlcat.c strlcpy.c strtonum.c tokenize.c trim.c vector.c
+SRC = emallocz.c estrdup.c strlcat.c strlcpy.c tokenize.c trim.c vector.c
OBJ = ${SRC:.c=.o}
diff --git a/libcext/cext.h b/libcext/cext.h
@@ -21,10 +21,6 @@ unsigned int cext_strlcat(char *dst, const char *src, unsigned int siz);
/* strlcpy.c */
unsigned int cext_strlcpy(char *dst, const char *src, unsigned int siz);
-/* strtonum.c */
-long long cext_strtonum(const char *numstr, long long minval,
- long long maxval, const char **errstrp);
-
/* tokenize.c */
unsigned int cext_tokenize(char **result, unsigned int reslen, char *str, char delim);
diff --git a/libcext/strtonum.c b/libcext/strtonum.c
@@ -1,65 +0,0 @@
-/*
- * Copyright (c) 2004 Ted Unangst and Todd Miller
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-#include <errno.h>
-#include <limits.h>
-#include <stdlib.h>
-
-enum {
- INVALID = 1,
- TOOSMALL = 2,
- TOOLARGE = 3
-};
-
-long long
-cext_strtonum(const char *numstr, long long minval, long long maxval,
- const char **errstrp)
-{
- long long ll = 0;
- char *ep;
- int error = 0;
- struct errval {
- const char *errstr;
- int err;
- } ev[4] = {
- {NULL, 0},
- {"invalid", EINVAL},
- {"too small", ERANGE},
- {"too large", ERANGE},
- };
-
- ev[0].err = errno;
- errno = 0;
- if(minval > maxval)
- error = INVALID;
- else {
- ll = strtoll(numstr, &ep, 10);
- if(numstr == ep || *ep != 0)
- error = INVALID;
- else if(errno == ERANGE || ll < minval)
- error = TOOSMALL;
- else if(errno == ERANGE || ll > maxval)
- error = TOOLARGE;
- }
- if(errstrp != NULL)
- *errstrp = ev[error].errstr;
- errno = ev[error].err;
- if(error)
- ll = 0;
-
- return (ll);
-}
diff --git a/libixp/socket.c b/libixp/socket.c
@@ -14,6 +14,7 @@
#include <netdb.h>
#include <sys/un.h>
#include <unistd.h>
+#include <errno.h>
#include "ixp.h"
@@ -45,16 +46,15 @@ connect_inet_sock(char *host)
struct sockaddr_in addr = { 0 };
struct hostent *hp;
char *port = strrchr(host, '!');
- const char *errstr = nil;
unsigned int prt;
if(!port)
return -1;
*port = 0;
port++;
- prt = cext_strtonum(port, 0, 65535, &errstr);
+ prt = strtol(port, nil, 10);
- if(errstr)
+ if(errno)
return -1;
/* init */
@@ -117,9 +117,11 @@ create_inet_sock(char *host, char **errstr)
}
*port = 0;
port++;
- prt = cext_strtonum(port, 1024, 65535, (const char **)errstr);
- if(*errstr)
+ prt = strtol(port, nil, 10);
+ if(errno) {
+ *errstr = "invalid port number";
return -1;
+ }
signal(SIGPIPE, SIG_IGN);
if((fd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
*errstr = "cannot open socket";