Compare commits
19 Commits
Author | SHA1 | Date | |
---|---|---|---|
a665c369e3
|
|||
f7b307bb34
|
|||
058547e707 | |||
68c1c4e511 | |||
f2c5daa9fe | |||
81533f966e | |||
b188c78432 | |||
d9bda20849 | |||
df4c061136 | |||
ec293427a0 | |||
9bb34de449 | |||
7f0141bbe9 | |||
6ae3c37e30 | |||
6d4fd01fc1 | |||
6703fe4592 | |||
5eaa0fff0d | |||
f87d3f5bef | |||
7cfa52d6eb | |||
16c1c2df60 |
21
.editorconfig
Normal file
21
.editorconfig
Normal file
@ -0,0 +1,21 @@
|
||||
root = true
|
||||
|
||||
[*]
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
end_of_line = lf
|
||||
charset = utf-8
|
||||
trim_trailing_whitespace = true
|
||||
insert_final_newline = true
|
||||
|
||||
[{*.c,*.h}]
|
||||
indent_style = tab
|
||||
indent_size = 4
|
||||
|
||||
[*.md]
|
||||
trim_trailing_whitespace = false
|
||||
indent_style = tab
|
||||
|
||||
[Makefile]
|
||||
indent_style = tab
|
||||
indent_size = 4
|
11
.hgtags
11
.hgtags
@ -1,11 +0,0 @@
|
||||
de32c537aaf66554894712563ffba8d9bc4c2714 0.1
|
||||
56350a01f27753cfbdbb3dbc25f2a53dd4c2ac45 0.2
|
||||
d77f00af559258679a0fad5d264685d663e6975a 0.3
|
||||
a3549fb4c72ff0edb816c8c29be7ff289db5b003 0.4
|
||||
70d49a37b35695f2f771bddaf309f05ea60af8bc 0.5
|
||||
d7923d9e717c1c6f1ed3b17ec90bfdd7e7bfcca0 0.6
|
||||
643a6e8b8634b70d2459637fcfff6eca776fc919 0.7
|
||||
07fb3efaa2e9ed18c6c16f0ddd8576cb66fec9c6 0.8
|
||||
96eb1bfede5b72fcee3f515d3113d814f7e87108 0.9
|
||||
b8794f3ed15e34b24ff9fb11c93a4405d0f91433 1.0
|
||||
d6140e3685b89c609a731471eba6787f7869aa59 1.1
|
3
LICENSE
3
LICENSE
@ -1,6 +1,7 @@
|
||||
MIT/X Consortium License
|
||||
|
||||
© 2005-2013 Anselm R Garbe <anselm@garbe.us>
|
||||
© 2022 Alexander Popov <iiiypuk@fastmail.fm>
|
||||
© 2005-2017 Anselm R Garbe <anselm@garbe.us>
|
||||
© 2008-2009 Jeroen Schot <schot@a-eskwadraat.nl>
|
||||
© 2007-2009 Kris Maglione <maglione.k@gmail.com>
|
||||
© 2005 Nico Golde <nico at ngolde dot de>
|
||||
|
81
Makefile
81
Makefile
@ -1,54 +1,59 @@
|
||||
# sic - simple irc client
|
||||
.POSIX:
|
||||
|
||||
include config.mk
|
||||
NAME = sic
|
||||
VERSION = 1.3
|
||||
|
||||
SRC = sic.c
|
||||
# paths
|
||||
PREFIX = /usr/local
|
||||
MANPREFIX = ${PREFIX}/share/man
|
||||
|
||||
# use system flags.
|
||||
SIC_CFLAGS = ${CFLAGS}
|
||||
SIC_LDFLAGS = ${LDFLAGS}
|
||||
SIC_CPPFLAGS = ${LDFLAGS} -DVERSION=\"${VERSION}\" -D_GNU_SOURCE
|
||||
|
||||
BIN = sic
|
||||
SRC = ${BIN:=.c}
|
||||
OBJ = ${SRC:.c=.o}
|
||||
MAN1 = ${BIN:=.1}
|
||||
|
||||
all: options sic
|
||||
all: ${BIN}
|
||||
|
||||
options:
|
||||
@echo sic build options:
|
||||
@echo "CFLAGS = ${CFLAGS}"
|
||||
@echo "LDFLAGS = ${LDFLAGS}"
|
||||
@echo "CC = ${CC}"
|
||||
${BIN}: ${@:=.o}
|
||||
|
||||
${OBJ}: config.h strlcpy.c util.c
|
||||
|
||||
.o:
|
||||
${CC} -o $@ $< ${SIC_LDFLAGS}
|
||||
|
||||
.c.o:
|
||||
@echo CC $<
|
||||
@${CC} -c ${CFLAGS} $<
|
||||
${CC} -c ${SIC_CFLAGS} ${SIC_CPPFLAGS} -o $@ -c $<
|
||||
|
||||
${OBJ}: config.mk util.c
|
||||
|
||||
sic: ${OBJ}
|
||||
@echo CC -o $@
|
||||
@${CC} -o $@ ${OBJ} ${LDFLAGS}
|
||||
config.h:
|
||||
cp config.def.h $@
|
||||
|
||||
clean:
|
||||
@echo cleaning
|
||||
@rm -f sic ${OBJ} sic-${VERSION}.tar.gz
|
||||
rm -f ${BIN} ${OBJ} "${NAME}-${VERSION}.tar.gz"
|
||||
|
||||
dist: clean
|
||||
@echo creating dist tarball
|
||||
@mkdir -p sic-${VERSION}
|
||||
@cp -R LICENSE Makefile README config.mk sic.1 sic.c util.c sic-${VERSION}
|
||||
@tar -cf sic-${VERSION}.tar sic-${VERSION}
|
||||
@gzip sic-${VERSION}.tar
|
||||
@rm -rf sic-${VERSION}
|
||||
dist:
|
||||
mkdir -p "${NAME}-${VERSION}"
|
||||
cp -fR LICENSE Makefile README arg.h config.def.h \
|
||||
${MAN1} ${SRC} util.c strlcpy.c "${NAME}-${VERSION}"
|
||||
tar -cf - "${NAME}-${VERSION}" | \
|
||||
gzip -c > "${NAME}-${VERSION}.tar.gz"
|
||||
rm -rf "${NAME}-${VERSION}"
|
||||
|
||||
install: all
|
||||
@echo installing executable file to ${DESTDIR}${PREFIX}/bin
|
||||
@mkdir -p ${DESTDIR}${PREFIX}/bin
|
||||
@cp -f sic ${DESTDIR}${PREFIX}/bin
|
||||
@chmod 755 ${DESTDIR}${PREFIX}/bin/sic
|
||||
@echo installing manual page to ${DESTDIR}${MANPREFIX}/man1
|
||||
@mkdir -p ${DESTDIR}${MANPREFIX}/man1
|
||||
@sed "s/VERSION/${VERSION}/g" < sic.1 > ${DESTDIR}${MANPREFIX}/man1/sic.1
|
||||
@chmod 644 ${DESTDIR}${MANPREFIX}/man1/sic.1
|
||||
mkdir -p ${DESTDIR}${PREFIX}/bin
|
||||
cp -f ${BIN} "${DESTDIR}${PREFIX}/bin"
|
||||
chmod 755 "${DESTDIR}${PREFIX}/bin/${BIN}"
|
||||
mkdir -p "${DESTDIR}${MANPREFIX}/man1"
|
||||
sed "s/VERSION/${VERSION}/g" < ${MAN1} > "${DESTDIR}${MANPREFIX}/man1/${MAN1}"
|
||||
chmod 644 "${DESTDIR}${MANPREFIX}/man1/${MAN1}"
|
||||
|
||||
uninstall:
|
||||
@echo removing executable file from ${DESTDIR}${PREFIX}/bin
|
||||
@rm -f ${DESTDIR}${PREFIX}/bin/sic
|
||||
@echo removing manual page from ${DESTDIR}${MANPREFIX}/man1
|
||||
@rm -f ${DESTDIR}${MANPREFIX}/man1/sic.1
|
||||
rm -f \
|
||||
"${DESTDIR}${PREFIX}/bin/${BIN}"\
|
||||
"${DESTDIR}${MANPREFIX}/man1/${MAN1}"
|
||||
|
||||
.PHONY: all options clean dist install uninstall
|
||||
.PHONY: all clean dist install uninstall
|
||||
|
22
README
22
README
@ -1,22 +0,0 @@
|
||||
sic - simple irc client
|
||||
=======================
|
||||
sic is an extremly fast, small and simple irc client. It reads commands from
|
||||
standard input and prints all server output to standard output. It multiplexes
|
||||
also all channel traffic into one output, that you don't have to switch
|
||||
different channel buffers, that's actually a feature.
|
||||
|
||||
|
||||
Installation
|
||||
------------
|
||||
Edit config.mk to match your local setup. sic is installed into
|
||||
/usr/local by default.
|
||||
|
||||
Afterwards enter the following command to build and install sic
|
||||
(if necessary as root):
|
||||
|
||||
$ make clean install
|
||||
|
||||
|
||||
Running sic
|
||||
-----------
|
||||
Simply invoke the 'sic' command with the required arguments.
|
23
README.md
Normal file
23
README.md
Normal file
@ -0,0 +1,23 @@
|
||||
sic - simple irc client
|
||||
=======================
|
||||
sic is an extremely fast, small and simple irc client. It reads commands from
|
||||
standard input and prints all server output to standard output. It multiplexes
|
||||
also all channel traffic into one output so that you don't have to switch
|
||||
different channel buffers: that's actually a feature.
|
||||
|
||||
|
||||
Installation
|
||||
------------
|
||||
Edit the Makefile or override the flags to match your local setup. sic is
|
||||
installed into /usr/local by default.
|
||||
|
||||
Afterwards enter the following command to build and install sic
|
||||
(if necessary as root):
|
||||
|
||||
$ make
|
||||
# make install
|
||||
|
||||
|
||||
Running sic
|
||||
-----------
|
||||
Simply invoke the `sic` command with the required arguments.
|
63
arg.h
Normal file
63
arg.h
Normal file
@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copy me if you can.
|
||||
* by 20h
|
||||
*/
|
||||
|
||||
#ifndef ARG_H__
|
||||
#define ARG_H__
|
||||
|
||||
extern char *argv0;
|
||||
|
||||
/* use main(int argc, char *argv[]) */
|
||||
#define ARGBEGIN for (argv0 = *argv, argv++, argc--;\
|
||||
argv[0] && argv[0][1]\
|
||||
&& argv[0][0] == '-';\
|
||||
argc--, argv++) {\
|
||||
char argc_;\
|
||||
char **argv_;\
|
||||
int brk_;\
|
||||
if (argv[0][1] == '-' && argv[0][2] == '\0') {\
|
||||
argv++;\
|
||||
argc--;\
|
||||
break;\
|
||||
}\
|
||||
for (brk_ = 0, argv[0]++, argv_ = argv;\
|
||||
argv[0][0] && !brk_;\
|
||||
argv[0]++) {\
|
||||
if (argv_ != argv)\
|
||||
break;\
|
||||
argc_ = argv[0][0];\
|
||||
switch (argc_)
|
||||
|
||||
/* Handles obsolete -NUM syntax */
|
||||
#define ARGNUM case '0':\
|
||||
case '1':\
|
||||
case '2':\
|
||||
case '3':\
|
||||
case '4':\
|
||||
case '5':\
|
||||
case '6':\
|
||||
case '7':\
|
||||
case '8':\
|
||||
case '9'
|
||||
|
||||
#define ARGEND }\
|
||||
}
|
||||
|
||||
#define ARGC() argc_
|
||||
|
||||
#define ARGNUMF(base) (brk_ = 1, estrtol(argv[0], (base)))
|
||||
|
||||
#define EARGF(x) ((argv[0][1] == '\0' && argv[1] == NULL)?\
|
||||
((x), abort(), (char *)0) :\
|
||||
(brk_ = 1, (argv[0][1] != '\0')?\
|
||||
(&argv[0][1]) :\
|
||||
(argc--, argv++, argv[0])))
|
||||
|
||||
#define ARGF() ((argv[0][1] == '\0' && argv[1] == NULL)?\
|
||||
(char *)0 :\
|
||||
(brk_ = 1, (argv[0][1] != '\0')?\
|
||||
(&argv[0][1]) :\
|
||||
(argc--, argv++, argv[0])))
|
||||
|
||||
#endif
|
14
config.def.h
Normal file
14
config.def.h
Normal file
@ -0,0 +1,14 @@
|
||||
/* Host used when "-h" is not given */
|
||||
#define DEFAULT_HOST "iiiypuk.me"
|
||||
|
||||
/* Port used when "-p" is not given */
|
||||
#define DEFAULT_PORT "6667"
|
||||
|
||||
/* Timestamp format; see strftime(3). */
|
||||
#define TIMESTAMP_FORMAT "%Y-%m-%d %R"
|
||||
|
||||
/* Command prefix character. In most IRC clients this is '/'. */
|
||||
#define COMMAND_PREFIX_CHARACTER ':'
|
||||
|
||||
/* Parting message used when none is specified with ":l ..." command. */
|
||||
#define DEFAULT_PARTING_MESSAGE "sic - 250 LOC are too much!"
|
20
config.mk
20
config.mk
@ -1,20 +0,0 @@
|
||||
# sic version
|
||||
VERSION = 1.2
|
||||
|
||||
# Customize below to fit your system
|
||||
|
||||
# paths
|
||||
PREFIX = /usr/local
|
||||
MANPREFIX = ${PREFIX}/share/man
|
||||
|
||||
# includes and libs
|
||||
INCS = -I. -I/usr/include
|
||||
LIBS = -L/usr/lib -lc
|
||||
|
||||
# flags
|
||||
CPPFLAGS = -DVERSION=\"${VERSION}\" -D_GNU_SOURCE
|
||||
CFLAGS = -std=c99 -pedantic -Wall -Os ${INCS} ${CPPFLAGS}
|
||||
LDFLAGS = -s ${LIBS}
|
||||
|
||||
# compiler and linker
|
||||
CC = cc
|
91
sic.c
91
sic.c
@ -1,4 +1,6 @@
|
||||
/* See LICENSE file for license details. */
|
||||
/* See LICENSE file for license details. */
|
||||
#include <sys/select.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <stdarg.h>
|
||||
@ -8,8 +10,12 @@
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
static char *host = "irc.oftc.net";
|
||||
static char *port = "6667";
|
||||
#include "arg.h"
|
||||
#include "config.h"
|
||||
|
||||
char *argv0;
|
||||
static char *host = DEFAULT_HOST;
|
||||
static char *port = DEFAULT_PORT;
|
||||
static char *password;
|
||||
static char nick[32];
|
||||
static char bufin[4096];
|
||||
@ -18,11 +24,13 @@ static char channel[256];
|
||||
static time_t trespond;
|
||||
static FILE *srv;
|
||||
|
||||
#undef strlcpy
|
||||
#include "strlcpy.c"
|
||||
#include "util.c"
|
||||
|
||||
static void
|
||||
pout(char *channel, char *fmt, ...) {
|
||||
static char timestr[18];
|
||||
static char timestr[80];
|
||||
time_t t;
|
||||
va_list ap;
|
||||
|
||||
@ -30,7 +38,7 @@ pout(char *channel, char *fmt, ...) {
|
||||
vsnprintf(bufout, sizeof bufout, fmt, ap);
|
||||
va_end(ap);
|
||||
t = time(NULL);
|
||||
strftime(timestr, sizeof timestr, "%D %R", localtime(&t));
|
||||
strftime(timestr, sizeof timestr, TIMESTAMP_FORMAT, localtime(&t));
|
||||
fprintf(stdout, "%-12s: %s %s\n", channel, timestr, bufout);
|
||||
}
|
||||
|
||||
@ -61,12 +69,12 @@ parsein(char *s) {
|
||||
if(s[0] == '\0')
|
||||
return;
|
||||
skip(s, '\n');
|
||||
if(s[0] != ':') {
|
||||
if(s[0] != COMMAND_PREFIX_CHARACTER) {
|
||||
privmsg(channel, s);
|
||||
return;
|
||||
}
|
||||
c = *++s;
|
||||
if(c != '\0' && isspace(s[1])) {
|
||||
if(c != '\0' && isspace((unsigned char)s[1])) {
|
||||
p = s + 2;
|
||||
switch(c) {
|
||||
case 'j':
|
||||
@ -82,7 +90,7 @@ parsein(char *s) {
|
||||
if(*p)
|
||||
*p++ = '\0';
|
||||
if(!*p)
|
||||
p = "sic - 250 LOC are too much!";
|
||||
p = DEFAULT_PARTING_MESSAGE;
|
||||
sout("PART %s :%s", s, p);
|
||||
return;
|
||||
case 'm':
|
||||
@ -131,40 +139,44 @@ parsesrv(char *cmd) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
usage(void) {
|
||||
eprint("usage: sic [-h host] [-p port] [-n nick] [-k keyword] [-v]\n", argv0);
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[]) {
|
||||
int i, c;
|
||||
struct timeval tv;
|
||||
const char *user = getenv("USER");
|
||||
int n;
|
||||
fd_set rd;
|
||||
|
||||
strlcpy(nick, user ? user : "unknown", sizeof nick);
|
||||
for(i = 1; i < argc; i++) {
|
||||
c = argv[i][1];
|
||||
if(argv[i][0] != '-' || argv[i][2])
|
||||
c = -1;
|
||||
switch(c) {
|
||||
case 'h':
|
||||
if(++i < argc) host = argv[i];
|
||||
break;
|
||||
case 'p':
|
||||
if(++i < argc) port = argv[i];
|
||||
break;
|
||||
case 'n':
|
||||
if(++i < argc) strlcpy(nick, argv[i], sizeof nick);
|
||||
break;
|
||||
case 'k':
|
||||
if(++i < argc) password = argv[i];
|
||||
break;
|
||||
case 'v':
|
||||
eprint("sic-"VERSION", © 2005-2012 Kris Maglione, Anselm R. Garbe, Nico Golde\n");
|
||||
default:
|
||||
eprint("usage: sic [-h host] [-p port] [-n nick] [-k keyword] [-v]\n");
|
||||
}
|
||||
}
|
||||
ARGBEGIN {
|
||||
case 'h':
|
||||
host = EARGF(usage());
|
||||
break;
|
||||
case 'p':
|
||||
port = EARGF(usage());
|
||||
break;
|
||||
case 'n':
|
||||
strlcpy(nick, EARGF(usage()), sizeof nick);
|
||||
break;
|
||||
case 'k':
|
||||
password = EARGF(usage());
|
||||
break;
|
||||
case 'v':
|
||||
eprint("sic-"VERSION", © 2005-2017 Anselm R Garbe, Jeroen Schot, Kris Maglione, Nico Golde\n");
|
||||
break;
|
||||
default:
|
||||
usage();
|
||||
} ARGEND;
|
||||
|
||||
/* init */
|
||||
i = dial(host, port);
|
||||
srv = fdopen(i, "r+");
|
||||
srv = fdopen(dial(host, port), "r+");
|
||||
if (!srv)
|
||||
eprint("fdopen:");
|
||||
/* login */
|
||||
if(password)
|
||||
sout("PASS %s", password);
|
||||
@ -173,19 +185,24 @@ main(int argc, char *argv[]) {
|
||||
fflush(srv);
|
||||
setbuf(stdout, NULL);
|
||||
setbuf(srv, NULL);
|
||||
setbuf(stdin, NULL);
|
||||
#ifdef __OpenBSD__
|
||||
if (pledge("stdio", NULL) == -1)
|
||||
eprint("error: pledge:");
|
||||
#endif
|
||||
for(;;) { /* main loop */
|
||||
FD_ZERO(&rd);
|
||||
FD_SET(0, &rd);
|
||||
FD_SET(fileno(srv), &rd);
|
||||
tv.tv_sec = 120;
|
||||
tv.tv_usec = 0;
|
||||
i = select(fileno(srv) + 1, &rd, 0, 0, &tv);
|
||||
if(i < 0) {
|
||||
n = select(fileno(srv) + 1, &rd, 0, 0, &tv);
|
||||
if(n < 0) {
|
||||
if(errno == EINTR)
|
||||
continue;
|
||||
eprint("sic: error on select():");
|
||||
}
|
||||
else if(i == 0) {
|
||||
else if(n == 0) {
|
||||
if(time(NULL) - trespond >= 300)
|
||||
eprint("sic shutting down: parse timeout\n");
|
||||
sout("PING %s", host);
|
||||
|
46
strlcpy.c
Normal file
46
strlcpy.c
Normal file
@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
|
||||
*
|
||||
* 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 <string.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
/*
|
||||
* Copy src to string dst of size siz. At most siz-1 characters
|
||||
* will be copied. Always NUL terminates (unless siz == 0).
|
||||
* Returns strlen(src); if retval >= siz, truncation occurred.
|
||||
*/
|
||||
size_t
|
||||
strlcpy(char *dst, const char *src, size_t siz)
|
||||
{
|
||||
char *d = dst;
|
||||
const char *s = src;
|
||||
size_t n = siz;
|
||||
/* Copy as many bytes as will fit */
|
||||
if (n != 0) {
|
||||
while (--n != 0) {
|
||||
if ((*d++ = *s++) == '\0')
|
||||
break;
|
||||
}
|
||||
}
|
||||
/* Not enough room in dst, add NUL and traverse rest of src */
|
||||
if (n == 0) {
|
||||
if (siz != 0)
|
||||
*d = '\0'; /* NUL-terminate dst */
|
||||
while (*s++)
|
||||
;
|
||||
}
|
||||
return(s - src - 1); /* count does not include NUL */
|
||||
}
|
28
util.c
28
util.c
@ -18,9 +18,9 @@ eprint(const char *fmt, ...) {
|
||||
|
||||
static int
|
||||
dial(char *host, char *port) {
|
||||
static struct addrinfo hints;
|
||||
int srv;
|
||||
struct addrinfo hints;
|
||||
struct addrinfo *res, *r;
|
||||
int fd;
|
||||
|
||||
memset(&hints, 0, sizeof hints);
|
||||
hints.ai_family = AF_UNSPEC;
|
||||
@ -28,28 +28,21 @@ dial(char *host, char *port) {
|
||||
if(getaddrinfo(host, port, &hints, &res) != 0)
|
||||
eprint("error: cannot resolve hostname '%s':", host);
|
||||
for(r = res; r; r = r->ai_next) {
|
||||
if((srv = socket(r->ai_family, r->ai_socktype, r->ai_protocol)) == -1)
|
||||
if((fd = socket(r->ai_family, r->ai_socktype, r->ai_protocol)) == -1)
|
||||
continue;
|
||||
if(connect(srv, r->ai_addr, r->ai_addrlen) == 0)
|
||||
if(connect(fd, r->ai_addr, r->ai_addrlen) == 0)
|
||||
break;
|
||||
close(srv);
|
||||
close(fd);
|
||||
}
|
||||
freeaddrinfo(res);
|
||||
if(!r)
|
||||
eprint("error: cannot connect to host '%s'\n", host);
|
||||
return srv;
|
||||
}
|
||||
|
||||
#define strlcpy _strlcpy
|
||||
static void
|
||||
strlcpy(char *to, const char *from, int l) {
|
||||
memccpy(to, from, '\0', l);
|
||||
to[l-1] = '\0';
|
||||
return fd;
|
||||
}
|
||||
|
||||
static char *
|
||||
eat(char *s, int (*p)(int), int r) {
|
||||
while(s != '\0' && p(*s) == r)
|
||||
while(*s != '\0' && p((unsigned char)*s) == r)
|
||||
s++;
|
||||
return s;
|
||||
}
|
||||
@ -67,8 +60,7 @@ static void
|
||||
trim(char *s) {
|
||||
char *e;
|
||||
|
||||
e = s + strlen(s) - 1;
|
||||
while(isspace(*e) && e > s)
|
||||
e--;
|
||||
*(e + 1) = '\0';
|
||||
for (e = s + strlen(s); e > s && isspace((unsigned char)*(e - 1)); e--)
|
||||
;
|
||||
*e = '\0';
|
||||
}
|
||||
|
Reference in New Issue
Block a user