1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-03-09 15:50:02 +00:00

Introduce usage of __builtin_unreachable() and noreturn (#248)

This commit adds an UNREACHABLE() macro that expands to either the
__builtin_unreachable() compiler builtin (for release builds) or
abort(3) (for development builds). This is used to mark code paths
that are never to be reached.

It also adds the 'noreturn' attribute to functions that never
return: path_exec(), sh_done() and sh_syntax(). The UNREACHABLE()
macro is not added after calling these.

The purpose of these is:
* to slightly improve GCC/Clang compiler optimizations;
* to fix a few compiler warnings;
* to add code clarity.

Changes of note:

src/cmd/ksh93/sh/io.c: outexcept():
- Avoid using __builtin_unreachable() here since errormsg can
  return despite using ERROR_system(1), as shp->jmplist->mode is
  temporarily set to 0. See: https://github.com/att/ast/issues/1336

src/cmd/ksh93/tests/io.sh:
- Add a regression test for the ksh2020 bug referenced above.

src/lib/libast/features/common:
- Detect the existence of either the C11 stdnoreturn.h header or
  the GCC noreturn attribute, preferring the former when available.
- Test for the existence of __builtin_unreachable(). Use it for
  release builds. On development builds, use abort() instead, which
  crahses reliably for debugging when unreachable code is reached.

Co-authored-by: Martijn Dekker <martijn@inlv.org>
This commit is contained in:
Johnothan King 2021-04-04 16:28:24 -07:00 committed by GitHub
parent 56913f8c2a
commit c4f980eb29
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
87 changed files with 1170 additions and 122 deletions

View file

@ -191,7 +191,7 @@ waitpid(pid_t pid, int* status, int flags)
zp->next = zombies;
zombies = zp;
}
/*NOTREACHED*/
UNREACHABLE();
}
#endif

View file

@ -55,7 +55,7 @@ readdir(register DIR* dirp)
dirp->dd_loc += dp->d_reclen;
if (dp->d_fileno) return(dp);
}
/*NOTREACHED*/
UNREACHABLE();
}
#endif

View file

@ -55,12 +55,12 @@ nomalloc(Vmalloc_t* region, int type, void* obj, Vmdisc_t* disc)
#ifdef VM_BADADDR
case VM_BADADDR:
error(ERROR_SYSTEM|3, "invalid pointer %p passed to free or realloc", obj);
return(-1);
UNREACHABLE();
#endif
case VM_NOMEM:
vmstat(region, &st);
error(ERROR_SYSTEM|3, "storage allocator out of memory on %lu byte request ( region %lu segments %lu busy %lu:%lu:%lu free %lu:%lu:%lu )", (size_t)obj, st.extent, st.n_seg, st.n_busy, st.s_busy, st.m_busy, st.n_free, st.s_free, st.m_free);
return(-1);
UNREACHABLE();
}
return(0);
}

View file

@ -1,5 +1,5 @@
iff AST_COMMON
hdr pthread,stdarg,stddef,stdint,inttypes,types,unistd
hdr pthread,stdarg,stddef,stdint,stdnoreturn,inttypes,types,unistd
sys types
typ long.double,size_t,ssize_t
typ __va_list stdio.h
@ -145,6 +145,16 @@ cat{
# define __EXTERN__(T,obj) extern T obj
# define __DEFINE__(T,obj,val) T obj = val
#endif
#if !_hdr_stdnoreturn
#if defined(__GNUC__) && (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4))
#define noreturn __attribute__((noreturn))
#else
#define noreturn
#endif /* __GNUC__ */
#else
#include <stdnoreturn.h>
#endif /* _hdr_stdnoreturn */
}end
if tst - note{ <stdarg.h>+<wchar.h> works }end compile{
@ -634,3 +644,37 @@ run{
#endif
!
}end
tst - note{ does this compiler have __builtin_unreachable() }end output{
/*
* To avoid optimizing out the __builtin_unreachable() test call while also avoiding
* executing it, put it in a test function that is called with argc as the argument.
* argc should never be zero on init, but hopefully optimizers aren't that smart.
*/
#include <stdio.h>
void testfn(int a)
{
switch(a)
{
case 0:
__builtin_unreachable();
default:
printf("#if _AST_ksh_release\n");
printf("# define UNREACHABLE()\t__builtin_unreachable()\n");
printf("#else\n");
printf("# define UNREACHABLE()\tabort()\n");
printf("#endif\n");
}
}
int main(int argc, char *argv[])
{
testfn(argc);
return 0;
}
}end fail{
echo '#if _AST_ksh_release'
echo '# define UNREACHABLE() 0'
echo '#else'
echo '# define UNREACHABLE() abort()'
echo '#endif'
}end

View file

@ -120,13 +120,12 @@ static const char Omsg[] = "malloc failed while growing stack\n";
/*
* default overflow exception
*/
static char *overflow(int n)
static noreturn char *overflow(int n)
{
NoP(n);
write(2,Omsg, sizeof(Omsg)-1);
exit(2);
/* NOTREACHED */
return(0);
UNREACHABLE();
}
/*

View file

@ -122,14 +122,17 @@ b_basename(int argc, register char** argv, Shbltin_t* context)
break;
case '?':
error(ERROR_usage(2), "%s", opt_info.arg);
break;
UNREACHABLE();
}
break;
}
argv += opt_info.index;
argc -= opt_info.index;
if (error_info.errors || argc < 1 || !all && argc > 2)
{
error(ERROR_usage(2), "%s", optusage(NiL));
UNREACHABLE();
}
if (!all)
namebase(sfstdout, argv[0], argv[1]);
else

View file

@ -463,7 +463,7 @@ b_cat(int argc, char** argv, Shbltin_t* context)
break;
case '?':
error(ERROR_usage(2), "%s", opt_info.arg);
break;
UNREACHABLE();
}
if (!n)
break;
@ -474,7 +474,10 @@ b_cat(int argc, char** argv, Shbltin_t* context)
}
argv += opt_info.index;
if (error_info.errors)
{
error(ERROR_usage(2), "%s", optusage(NiL));
UNREACHABLE();
}
memset(states, 0, sizeof(states));
if (flags&V_FLAG)
{

View file

@ -179,7 +179,10 @@ getids(register char* s, char** e, Key_t* key, int options)
if ((m = struid(s)) != NOID)
n = m;
else if (*z)
{
error(ERROR_exit(1), "%s: unknown user", s);
UNREACHABLE();
}
}
key->uid = n;
}
@ -199,7 +202,10 @@ getids(register char* s, char** e, Key_t* key, int options)
if ((m = strgid(s)) != NOID)
n = m;
else if (*z)
{
error(ERROR_exit(1), "%s: unknown group", s);
UNREACHABLE();
}
}
key->gid = n;
}
@ -241,7 +247,10 @@ b_chgrp(int argc, char** argv, Shbltin_t* context)
flags = fts_flags() | FTS_META | FTS_TOP | FTS_NOPOSTORDER | FTS_NOSEEDOTDIR;
before = ~0;
if (!(sp = sfstropen()))
{
error(ERROR_SYSTEM|3, "out of space");
UNREACHABLE();
}
sfputr(sp, usage_1, -1);
if (error_info.id[2] == 'g')
sfputr(sp, usage_grp_1, -1);
@ -257,14 +266,20 @@ b_chgrp(int argc, char** argv, Shbltin_t* context)
sfputr(sp, ERROR_translate(0, 0, 0, "[[owner:]group]"), -1);
sfputr(sp, usage_3, -1);
if (!(usage = sfstruse(sp)))
{
error(ERROR_SYSTEM|3, "out of space");
UNREACHABLE();
}
for (;;)
{
switch (optget(argv, usage))
{
case 'b':
if (stat(opt_info.arg, &st))
{
error(ERROR_exit(1), "%s: cannot stat", opt_info.arg);
UNREACHABLE();
}
before = st.st_mtime;
continue;
case 'c':
@ -282,7 +297,10 @@ b_chgrp(int argc, char** argv, Shbltin_t* context)
mapdisc.key = offsetof(Map_t, key);
mapdisc.size = sizeof(Key_t);
if (!(map = dtopen(&mapdisc, Dtset)))
{
error(ERROR_exit(1), "out of memory [id map]");
UNREACHABLE();
}
continue;
case 'n':
options |= OPT_SHOW;
@ -292,7 +310,10 @@ b_chgrp(int argc, char** argv, Shbltin_t* context)
continue;
case 'r':
if (stat(opt_info.arg, &st))
{
error(ERROR_exit(1), "%s: cannot stat", opt_info.arg);
UNREACHABLE();
}
uid = st.st_uid;
gid = st.st_gid;
options |= OPT_UID|OPT_GID;
@ -325,14 +346,17 @@ b_chgrp(int argc, char** argv, Shbltin_t* context)
continue;
case '?':
error(ERROR_usage(2), "%s", opt_info.arg);
break;
UNREACHABLE();
}
break;
}
argv += opt_info.index;
argc -= opt_info.index;
if (error_info.errors || argc < 2)
{
error(ERROR_usage(2), "%s", optusage(NiL));
UNREACHABLE();
}
s = *argv;
if (options & OPT_LCHOWN)
{
@ -347,14 +371,20 @@ b_chgrp(int argc, char** argv, Shbltin_t* context)
if (streq(s, "-"))
sp = sfstdin;
else if (!(sp = sfopen(NiL, s, "r")))
{
error(ERROR_exit(1), "%s: cannot read", s);
UNREACHABLE();
}
while (s = sfgetr(sp, '\n', 1))
{
getids(s, &t, &key, options);
if (!(m = (Map_t*)dtmatch(map, &key)))
{
if (!(m = (Map_t*)stakalloc(sizeof(Map_t))))
{
error(ERROR_exit(1), "out of memory [id dictionary]");
UNREACHABLE();
}
m->key = key;
m->to.uid = m->to.gid = NOID;
dtinsert(map, m);
@ -389,7 +419,10 @@ b_chgrp(int argc, char** argv, Shbltin_t* context)
break;
}
if (!(fts = fts_open(argv + 1, flags, NiL)))
{
error(ERROR_system(1), "%s: not found", argv[1]);
UNREACHABLE();
}
while (!sh_checksig(context) && (ent = fts_read(fts)))
switch (ent->fts_info)
{

View file

@ -202,7 +202,10 @@ b_chmod(int argc, char** argv, Shbltin_t* context)
continue;
case 'F':
if (stat(opt_info.arg, &st))
{
error(ERROR_exit(1), "%s: cannot stat", opt_info.arg);
UNREACHABLE();
}
mode = st.st_mode;
amode = "";
continue;
@ -225,13 +228,16 @@ b_chmod(int argc, char** argv, Shbltin_t* context)
continue;
case '?':
error(ERROR_usage(2), "%s", opt_info.arg);
break;
UNREACHABLE();
}
break;
}
argv += opt_info.index;
if (error_info.errors || !*argv || !amode && !*(argv + 1))
{
error(ERROR_usage(2), "%s", optusage(NiL));
UNREACHABLE();
}
if (chlink)
{
flags &= ~FTS_META;
@ -253,6 +259,7 @@ b_chmod(int argc, char** argv, Shbltin_t* context)
if (ignore)
umask(ignore);
error(ERROR_exit(1), "%s: invalid mode", amode);
UNREACHABLE();
}
}
if (!(fts = fts_open(argv, flags, NiL)))
@ -260,6 +267,7 @@ b_chmod(int argc, char** argv, Shbltin_t* context)
if (ignore)
umask(ignore);
error(ERROR_system(1), "%s: not found", *argv);
UNREACHABLE();
}
while (!sh_checksig(context) && (ent = fts_read(fts)))
switch (ent->fts_info)

View file

@ -307,7 +307,10 @@ verify(State_t* state, register char* s, char* check, Sfio_t* rp)
{
pr(state, rp, sp, file, -1, NiL, NiL);
if (!(t = sfstruse(rp)))
{
error(ERROR_SYSTEM|3, "out of space");
UNREACHABLE();
}
if (!streq(s, t))
{
if (state->silent)
@ -528,8 +531,8 @@ b_cksum(int argc, register char** argv, Shbltin_t* context)
state.text = 1;
continue;
case '?':
error(ERROR_USAGE|4, "%s", opt_info.arg);
break;
error(ERROR_usage(2), "%s", opt_info.arg);
UNREACHABLE();
case ':':
error(2, "%s", opt_info.arg);
break;
@ -538,7 +541,10 @@ b_cksum(int argc, register char** argv, Shbltin_t* context)
}
argv += opt_info.index;
if (error_info.errors)
error(ERROR_USAGE|4, "%s", optusage(NiL));
{
error(ERROR_usage(2), "%s", optusage(NiL));
UNREACHABLE();
}
/*
* check the method
@ -590,7 +596,10 @@ b_cksum(int argc, register char** argv, Shbltin_t* context)
else if (!*argv && !state.recursive)
pr(&state, sfstdout, sfstdin, "/dev/stdin", state.permissions, NiL, state.check);
else if (!(fts = fts_open(argv, flags, state.sort)))
{
error(ERROR_system(1), "%s: not found", *argv);
UNREACHABLE();
}
else
{
while (!sh_checksig(context) && (ent = fts_read(fts)))

View file

@ -165,15 +165,24 @@ cmp(const char* file1, Sfio_t* f1, const char* file2, Sfio_t* f2, int flags, Sfo
if (!(p1 = (unsigned char*)sfreserve(f1, SF_UNBOUND, 0)) || (c1 = sfvalue(f1)) <= 0)
{
if (sferror(f1))
{
error(ERROR_exit(2), "read error on %s", file1);
UNREACHABLE();
}
if ((e2 - p2) > 0 || sfreserve(f2, SF_UNBOUND, 0) && sfvalue(f2) > 0)
{
ret = 1;
if (!(flags & CMP_SILENT))
{
error(ERROR_exit(1), "EOF on %s", file1);
UNREACHABLE();
}
}
if (sferror(f2))
{
error(ERROR_exit(2), "read error on %s", file2);
UNREACHABLE();
}
return ret;
}
if (count > 0 && c1 > count)
@ -186,9 +195,15 @@ cmp(const char* file1, Sfio_t* f1, const char* file2, Sfio_t* f2, int flags, Sfo
if (!(p2 = (unsigned char*)sfreserve(f2, SF_UNBOUND, 0)) || (c2 = sfvalue(f2)) <= 0)
{
if (sferror(f2))
{
error(ERROR_exit(2), "read error on %s", file2);
UNREACHABLE();
}
if (!(flags & CMP_SILENT))
{
error(ERROR_exit(1), "EOF on %s", file2);
UNREACHABLE();
}
return 1;
}
e2 = p2 + c2;
@ -311,13 +326,16 @@ b_cmp(int argc, register char** argv, Shbltin_t* context)
break;
case '?':
error(ERROR_usage(2), "%s", opt_info.arg);
break;
UNREACHABLE();
}
break;
}
argv += opt_info.index;
if (error_info.errors || !(file1 = *argv++) || !(file2 = *argv++))
{
error(ERROR_usage(2), "%s", optusage(NiL));
UNREACHABLE();
}
n = 2;
if (streq(file1, "-"))
f1 = sfstdin;

View file

@ -170,28 +170,40 @@ b_comm(int argc, char *argv[], Shbltin_t* context)
break;
case '?':
error(ERROR_usage(2), "%s",opt_info.arg);
break;
UNREACHABLE();
}
break;
}
argv += opt_info.index;
argc -= opt_info.index;
if(error_info.errors || argc!=2)
{
error(ERROR_usage(2),"%s",optusage(NiL));
UNREACHABLE();
}
cp = *argv++;
if(streq(cp,"-"))
f1 = sfstdin;
else if(!(f1 = sfopen(NiL, cp,"r")))
{
error(ERROR_system(1),"%s: cannot open",cp);
UNREACHABLE();
}
cp = *argv;
if(streq(cp,"-"))
f2 = sfstdin;
else if(!(f2 = sfopen(NiL, cp,"r")))
{
error(ERROR_system(1),"%s: cannot open",cp);
UNREACHABLE();
}
if(mode)
{
if(comm(f1,f2,sfstdout,mode) < 0)
{
error(ERROR_system(1)," write error");
UNREACHABLE();
}
}
else if(f1==sfstdin || f2==sfstdin)
sfseek(sfstdin,(Sfoff_t)0,SEEK_END);

View file

@ -289,7 +289,10 @@ visit(State_t* state, register FTSENT* ent)
if (state->directory)
{
if ((state->postsiz + len) > state->pathsiz && !(state->path = newof(state->path, char, state->pathsiz = roundof(state->postsiz + len, PATH_CHUNK), 0)))
{
error(ERROR_SYSTEM|3, "out of memory");
UNREACHABLE();
}
if (state->hierarchy && ent->fts_level == 0 && strchr(base, '/'))
{
s = state->path + state->postsiz;
@ -525,7 +528,10 @@ visit(State_t* state, register FTSENT* ent)
sfprintf(state->tmp, "%s%s", state->path, state->suffix);
backup:
if (!(s = sfstruse(state->tmp)))
{
error(ERROR_SYSTEM|3, "%s: out of space", state->path);
UNREACHABLE();
}
if (rename(state->path, s))
{
error(ERROR_SYSTEM|2, "%s: cannot backup to %s", state->path, s);
@ -688,7 +694,10 @@ b_cp(int argc, register char** argv, Shbltin_t* context)
if (!(sh = CMD_CONTEXT(context)) || !(state = (State_t*)sh->ptr))
{
if (!(state = newof(0, State_t, 1, 0)))
{
error(ERROR_SYSTEM|3, "out of memory");
UNREACHABLE();
}
if (sh)
sh->ptr = state;
}
@ -701,7 +710,10 @@ b_cp(int argc, register char** argv, Shbltin_t* context)
state->uid = geteuid();
state->wflags = O_WRONLY|O_CREAT|O_TRUNC|O_BINARY;
if (!state->tmp && !(state->tmp = sfstropen()))
{
error(ERROR_SYSTEM|3, "out of space [tmp string]");
UNREACHABLE();
}
sfputr(state->tmp, usage_head, -1);
standard = !!conformance(0, 0);
switch (error_info.id[0])
@ -738,7 +750,10 @@ b_cp(int argc, register char** argv, Shbltin_t* context)
}
sfputr(state->tmp, usage_tail, -1);
if (!(usage = sfstruse(state->tmp)))
{
error(ERROR_SYSTEM|3, "%s: out of space", state->path);
UNREACHABLE();
}
state->opname = state->op == CP ? ERROR_translate(0, 0, 0, "overwrite") : ERROR_translate(0, 0, 0, "replace");
for (;;)
{
@ -873,7 +888,10 @@ b_cp(int argc, register char** argv, Shbltin_t* context)
argv++;
}
if (!(v = (char**)stkalloc(stkstd, (argc + 2) * sizeof(char*))))
{
error(ERROR_SYSTEM|3, "out of memory");
UNREACHABLE();
}
memcpy(v, argv, (argc + 1) * sizeof(char*));
argv = v;
if (!standard)
@ -940,7 +958,10 @@ b_cp(int argc, register char** argv, Shbltin_t* context)
state->suflen = strlen(state->suffix);
}
if (argc <= 0 || error_info.errors)
error(ERROR_USAGE|4, "%s", optusage(NiL));
{
error(ERROR_usage(2), "%s", optusage(NiL));
UNREACHABLE();
}
if (!path_resolve)
state->flags |= fts_flags() | FTS_META;
file = argv[argc];
@ -955,12 +976,18 @@ b_cp(int argc, register char** argv, Shbltin_t* context)
if (file != (char*)dot)
pathcanon(file, 0, 0);
if (!(state->directory = !stat(file, &st) && S_ISDIR(st.st_mode)) && argc > 1)
error(ERROR_USAGE|4, "%s", optusage(NiL));
{
error(ERROR_usage(2), "%s", optusage(NiL));
UNREACHABLE();
}
if (s && !state->directory)
error(3, "%s: not a directory", file);
state->postsiz = strlen(file);
if (state->pathsiz < roundof(state->postsiz + 2, PATH_CHUNK) && !(state->path = newof(state->path, char, state->pathsiz = roundof(state->postsiz + 2, PATH_CHUNK), 0)))
{
error(ERROR_SYSTEM|3, "out of memory");
UNREACHABLE();
}
memcpy(state->path, file, state->postsiz + 1);
if (state->directory && state->path[state->postsiz - 1] != '/')
state->path[state->postsiz++] = '/';

View file

@ -138,7 +138,10 @@ cutinit(int mode, char* str, Delim_t* wdelim, Delim_t* ldelim, size_t reclen)
Cut_t* cut;
if (!(cut = (Cut_t*)stakalloc(sizeof(Cut_t) + strlen(cp) * sizeof(int))))
{
error(ERROR_exit(1), "out of memory");
UNREACHABLE();
}
if (cut->mb = mbwide())
{
memset(cut->space, 0, sizeof(cut->space) / 2);
@ -172,7 +175,10 @@ cutinit(int mode, char* str, Delim_t* wdelim, Delim_t* ldelim, size_t reclen)
{
--range;
if((n = (n ? (n-range) : (HUGE-1))) < 0)
{
error(ERROR_exit(1),"invalid range for c/f option");
UNREACHABLE();
}
*lp++ = range;
*lp++ = n;
}
@ -230,18 +236,24 @@ cutinit(int mode, char* str, Delim_t* wdelim, Delim_t* ldelim, size_t reclen)
case '-':
if(range)
{
error(ERROR_exit(1),"bad list for c/f option");
UNREACHABLE();
}
range = n?n:1;
n = 0;
break;
default:
if(!isdigit(c))
{
error(ERROR_exit(1),"bad list for c/f option");
UNREACHABLE();
}
n = 10*n + (c-'0');
break;
}
/* NOTREACHED */
UNREACHABLE();
}
/*
@ -659,17 +671,21 @@ b_cut(int argc, char** argv, Shbltin_t* context)
break;
case '?':
error(ERROR_usage(2), "%s", opt_info.arg);
break;
UNREACHABLE();
}
break;
}
argv += opt_info.index;
if (error_info.errors)
{
error(ERROR_usage(2), "%s",optusage(NiL));
UNREACHABLE();
}
if(!cp)
{
error(2, "b, c or f option must be specified");
error(ERROR_usage(2), "%s", optusage(NiL));
UNREACHABLE();
}
if(!*cp)
error(3, "non-empty b, c or f option must be specified");

View file

@ -341,7 +341,10 @@ b_date(int argc, register char** argv, Shbltin_t* context)
continue;
case 'p':
if (!(f = newof(0, Fmt_t, 1, 0)))
{
error(ERROR_SYSTEM|3, "out of memory [format]");
UNREACHABLE();
}
f->next = fmts;
f->format = opt_info.arg;
fmts = f;
@ -376,8 +379,8 @@ b_date(int argc, register char** argv, Shbltin_t* context)
listzones = tm_data.zone;
continue;
case '?':
error(ERROR_USAGE|4, "%s", opt_info.arg);
continue;
error(ERROR_usage(2), "%s", opt_info.arg);
UNREACHABLE();
case ':':
error(2, "%s", opt_info.arg);
continue;
@ -386,7 +389,10 @@ b_date(int argc, register char** argv, Shbltin_t* context)
}
argv += opt_info.index;
if (error_info.errors)
error(ERROR_USAGE|4, "%s", optusage(NiL));
{
error(ERROR_usage(2), "%s", optusage(NiL));
UNREACHABLE();
}
now = tmxgettime();
if (listzones)
{
@ -434,7 +440,10 @@ b_date(int argc, register char** argv, Shbltin_t* context)
else if (filetime)
{
if (!*argv)
error(ERROR_USAGE|4, "%s", optusage(NiL));
{
error(ERROR_usage(2), "%s", optusage(NiL));
UNREACHABLE();
}
n = argv[1] != 0;
while (s = *argv++)
{
@ -474,7 +483,10 @@ b_date(int argc, register char** argv, Shbltin_t* context)
if (s || (s = string))
{
if (*argv && string)
error(ERROR_USAGE|4, "%s", optusage(NiL));
{
error(ERROR_usage(2), "%s", optusage(NiL));
UNREACHABLE();
}
now = convert(fmts, s, now);
if (*argv && (s = *++argv))
{
@ -498,7 +510,10 @@ b_date(int argc, register char** argv, Shbltin_t* context)
sfprintf(sfstdout, "%s\n", buf);
}
else if (settime(context, cmd, now, increment, network))
{
error(ERROR_SYSTEM|3, "cannot set system time");
UNREACHABLE();
}
}
while (fmts != &fmt)
{

View file

@ -121,14 +121,17 @@ b_dirname(int argc, char** argv, Shbltin_t* context)
break;
case '?':
error(ERROR_usage(2), "%s", opt_info.arg);
break;
UNREACHABLE();
}
break;
}
argv += opt_info.index;
argc -= opt_info.index;
if(error_info.errors || argc != 1)
{
error(ERROR_usage(2),"%s", optusage(NiL));
UNREACHABLE();
}
if(!mode)
l_dirname(sfstdout,argv[0]);
else if(pathpath(argv[0], "", mode, buf, sizeof(buf)))

View file

@ -193,7 +193,10 @@ static int getnode(State_t* state, Node_t *np)
char* ep;
if (!(cp = *state->arglist++))
{
error(ERROR_exit(2), "argument expected");
UNREACHABLE();
}
if (!state->standard)
switch (cp[0])
{
@ -201,9 +204,15 @@ static int getnode(State_t* state, Node_t *np)
if (cp[1] == 'n' && !strcmp(cp, "index"))
{
if (!(cp = *state->arglist++))
{
error(ERROR_exit(2), "string argument expected");
UNREACHABLE();
}
if (!(ep = *state->arglist++))
{
error(ERROR_exit(2), "chars argument expected");
UNREACHABLE();
}
np->num = (ep = strpbrk(cp, ep)) ? (ep - cp + 1) : 0;
np->type = T_NUM;
goto next;
@ -213,7 +222,10 @@ static int getnode(State_t* state, Node_t *np)
if (cp[1] == 'e' && !strcmp(cp, "length"))
{
if (!(cp = *state->arglist++))
{
error(ERROR_exit(2), "string argument expected");
UNREACHABLE();
}
np->num = strlen(cp);
np->type = T_NUM;
goto next;
@ -223,27 +235,42 @@ static int getnode(State_t* state, Node_t *np)
if (cp[1] == 'a' && !strcmp(cp, "match"))
{
if (!(np->str = *state->arglist++))
{
error(ERROR_exit(2), "pattern argument expected");
UNREACHABLE();
}
np->type = T_STR;
return ':';
}
break;
case 'q':
if (cp[1] == 'u' && !strcmp(cp, "quote") && !(cp = *state->arglist++))
{
error(ERROR_exit(2), "string argument expected");
UNREACHABLE();
}
break;
case 's':
if (cp[1] == 'u' && !strcmp(cp, "substr"))
{
if (!(sp = *state->arglist++))
{
error(ERROR_exit(2), "string argument expected");
UNREACHABLE();
}
if (!(cp = *state->arglist++))
{
error(ERROR_exit(2), "position argument expected");
UNREACHABLE();
}
i = strtol(cp, &ep, 10);
if (*ep || --i < 0)
i = -1;
if (!(cp = *state->arglist++))
{
error(ERROR_exit(2), "length argument expected");
UNREACHABLE();
}
j = strtol(cp, &ep, 10);
if (*ep)
j = -1;
@ -267,7 +294,10 @@ static int getnode(State_t* state, Node_t *np)
{
tok = expr_or(state, np);
if (tok != ')')
{
error(ERROR_exit(2),"closing parenthesis missing");
UNREACHABLE();
}
}
else
{
@ -288,7 +318,7 @@ static int getnode(State_t* state, Node_t *np)
if (*cp==optable[i].opname[0] && cp[1]==optable[i].opname[1])
return optable[i].op;
error(ERROR_exit(2),"%s: unknown operator argument",cp);
return 0;
UNREACHABLE();
}
static int expr_cond(State_t* state, Node_t *np)
@ -352,9 +382,15 @@ static int expr_mult(State_t* state, Node_t *np)
int op = (tok&T_OP);
tok = expr_cond(state, &rp);
if (!numeric(np) || !numeric(&rp))
{
error(ERROR_exit(2),"non-numeric argument");
UNREACHABLE();
}
if (op && rp.num==0)
{
error(ERROR_exit(2),"division by zero");
UNREACHABLE();
}
switch(op)
{
case 0:
@ -381,7 +417,10 @@ static int expr_add(State_t* state, Node_t *np)
int op = (tok&T_OP);
tok = expr_mult(state, &rp);
if (!numeric(np) || !numeric(&rp))
{
error(ERROR_exit(2),"non-numeric argument");
UNREACHABLE();
}
if (op)
np->num -= rp.num;
else
@ -513,17 +552,27 @@ b_expr(int argc, char** argv, Shbltin_t* context)
* unknown - options
*/
if(n=='?')
{
error(ERROR_usage(2), "%s", opt_info.arg);
UNREACHABLE();
}
if (opt_info.option[1] != '?')
break;
error(ERROR_usage(2), "%s", opt_info.arg);
UNREACHABLE();
}
if (error_info.errors)
{
error(ERROR_usage(2),"%s",optusage((char*)0));
UNREACHABLE();
}
state.arglist = argv+opt_info.index;
}
if (expr_or(&state, &node))
{
error(ERROR_exit(2),"syntax error");
UNREACHABLE();
}
if (node.type&T_STR)
{
if (*node.str)

View file

@ -199,8 +199,8 @@ b_fds(int argc, char** argv, Shbltin_t* context)
unit = opt_info.num;
continue;
case '?':
error(ERROR_USAGE|4, "%s", opt_info.arg);
break;
error(ERROR_usage(2), "%s", opt_info.arg);
UNREACHABLE();
case ':':
error(2, "%s", opt_info.arg);
break;
@ -209,13 +209,19 @@ b_fds(int argc, char** argv, Shbltin_t* context)
}
argv += opt_info.index;
if (error_info.errors || *argv)
error(ERROR_USAGE|4, "%s", optusage(NiL));
{
error(ERROR_usage(2), "%s", optusage(NiL));
UNREACHABLE();
}
if ((open_max = getconf("OPEN_MAX")) <= 0)
open_max = OPEN_MAX;
if (unit == 1)
sp = sfstdout;
else if (fstat(unit, &st) || !(sp = sfnew(NiL, NiL, SF_UNBOUND, unit, SF_WRITE)))
{
error(ERROR_SYSTEM|3, "%d: cannot write to file descriptor");
UNREACHABLE();
}
for (i = 0; i <= open_max; i++)
{
if (fstat(i, &st))

View file

@ -602,13 +602,16 @@ b_fmt(int argc, char** argv, Shbltin_t* context)
break;
case '?':
error(ERROR_usage(2), "%s", opt_info.arg);
break;
UNREACHABLE();
}
break;
}
argv += opt_info.index;
if (error_info.errors)
{
error(ERROR_usage(2), "%s", optusage(NiL));
UNREACHABLE();
}
if (isoption(&fmt, 'o'))
setoption(&fmt, 'c');
if (isoption(&fmt, 's'))

View file

@ -211,14 +211,17 @@ b_fold(int argc, char** argv, Shbltin_t* context)
continue;
case '?':
error(ERROR_usage(2), "%s", opt_info.arg);
continue;
UNREACHABLE();
}
break;
}
argv += opt_info.index;
argc -= opt_info.index;
if(error_info.errors)
{
error(ERROR_usage(2),"%s", optusage(NiL));
UNREACHABLE();
}
if(cp = *argv)
argv++;
do

View file

@ -219,7 +219,7 @@ b_getconf(int argc, char** argv, Shbltin_t* context)
break;
case '?':
error(ERROR_usage(2), "%s", opt_info.arg);
break;
UNREACHABLE();
}
break;
}
@ -237,7 +237,10 @@ b_getconf(int argc, char** argv, Shbltin_t* context)
}
}
if (error_info.errors || !name && *argv)
{
error(ERROR_usage(2), "%s", optusage(NiL));
UNREACHABLE();
}
if (!name)
astconflist(sfstdout, path, flags, pattern);
else

View file

@ -108,7 +108,7 @@ b_head(int argc, register char** argv, Shbltin_t* context)
continue;
case '?':
error(ERROR_usage(2), "%s", opt_info.arg);
continue;
UNREACHABLE();
case ':':
error(2, "%s", opt_info.arg);
continue;
@ -118,7 +118,10 @@ b_head(int argc, register char** argv, Shbltin_t* context)
argv += opt_info.index;
argc -= opt_info.index;
if (error_info.errors)
{
error(ERROR_usage(2), "%s", optusage(NiL));
UNREACHABLE();
}
if (cp = *argv)
argv++;
do

View file

@ -232,7 +232,10 @@ getids(Sfio_t* sp, const char* name, register int flags)
if ((maxgroups = getgroups(0, groups)) <= 0)
maxgroups = NGROUPS_MAX;
if (!(groups = newof(0, gid_t, maxgroups + 1, 0)))
{
error(ERROR_exit(1), "out of memory [group array]");
UNREACHABLE();
}
}
ngroups = getgroups(maxgroups, groups);
for (i = j = 0; i < ngroups; i++)
@ -251,7 +254,10 @@ getids(Sfio_t* sp, const char* name, register int flags)
{
user = strtol(name, &s, 0);
if (*s || !(pw = getpwuid(user)))
{
error(ERROR_exit(1), "%s: name not found", name);
UNREACHABLE();
}
name = pw->pw_name;
}
user = pw->pw_uid;
@ -264,7 +270,10 @@ getids(Sfio_t* sp, const char* name, register int flags)
do
{
if (!(fs = getfsgnam(name)))
{
error(ERROR_exit(1), "%u: fss name not found", name);
UNREACHABLE();
}
} while (isfsg(fs));
fs_id = fs->fs_id;
}
@ -451,7 +460,7 @@ b_id(int argc, char** argv, Shbltin_t* context)
break;
case '?':
error(ERROR_usage(2), "%s", opt_info.arg);
break;
UNREACHABLE();
}
break;
}
@ -461,7 +470,10 @@ b_id(int argc, char** argv, Shbltin_t* context)
if (!power2(n))
error(2, "incompatible options selected");
if (error_info.errors || argc > 1)
{
error(ERROR_usage(2), "%s", optusage(NiL));
UNREACHABLE();
}
if (!(flags & ~(N_FLAG|R_FLAG)))
{
if (flags & N_FLAG) flags |= O_FLAG;

View file

@ -824,7 +824,10 @@ b_join(int argc, char** argv, Shbltin_t* context)
cmdinit(argc, argv, context, ERROR_CATALOG, ERROR_NOTIFY);
#endif
if (!(jp = init()))
{
error(ERROR_system(1),"out of memory");
UNREACHABLE();
}
jp->context = context;
for (;;)
{
@ -918,7 +921,7 @@ b_join(int argc, char** argv, Shbltin_t* context)
case '?':
done(jp);
error(ERROR_usage(2), "%s", opt_info.arg);
break;
UNREACHABLE();
}
break;
}
@ -928,6 +931,7 @@ b_join(int argc, char** argv, Shbltin_t* context)
{
done(jp);
error(ERROR_usage(2),"%s", optusage(NiL));
UNREACHABLE();
}
jp->ooutmode = jp->outmode;
jp->file[0].name = cp = *argv++;
@ -946,6 +950,7 @@ b_join(int argc, char** argv, Shbltin_t* context)
{
done(jp);
error(ERROR_system(1),"%s: cannot open",cp);
UNREACHABLE();
}
jp->file[1].name = cp = *argv;
if (streq(cp,"-"))
@ -963,6 +968,7 @@ b_join(int argc, char** argv, Shbltin_t* context)
{
done(jp);
error(ERROR_system(1),"%s: cannot open",cp);
UNREACHABLE();
}
if (jp->buffered)
{
@ -976,6 +982,7 @@ b_join(int argc, char** argv, Shbltin_t* context)
{
done(jp);
error(ERROR_system(1),"write error");
UNREACHABLE();
}
else if (jp->file[0].iop==sfstdin || jp->file[1].iop==sfstdin)
sfseek(sfstdin,(Sfoff_t)0,SEEK_END);

View file

@ -64,12 +64,15 @@ b_logname(int argc, char** argv, Shbltin_t* context)
continue;
case '?':
error(ERROR_usage(2), "%s", opt_info.arg);
continue;
UNREACHABLE();
}
break;
}
if (error_info.errors)
{
error(ERROR_usage(2), "%s", optusage(NiL));
UNREACHABLE();
}
if (!(logname = getlogin()))
logname = fmtuid(getuid());
sfputr(sfstdout, logname, '\n');

View file

@ -98,13 +98,16 @@ b_mkdir(int argc, char** argv, Shbltin_t* context)
break;
case '?':
error(ERROR_usage(2), "%s", opt_info.arg);
break;
UNREACHABLE();
}
break;
}
argv += opt_info.index;
if (error_info.errors || !*argv)
{
error(ERROR_usage(2), "%s", optusage(NiL));
UNREACHABLE();
}
mask = umask(0);
if (mflag || pflag)
{

View file

@ -73,13 +73,16 @@ b_mkfifo(int argc, char** argv, Shbltin_t* context)
break;
case '?':
error(ERROR_usage(2), "%s", opt_info.arg);
break;
UNREACHABLE();
}
break;
}
argv += opt_info.index;
if (error_info.errors || !*argv)
{
error(ERROR_usage(2), "%s", optusage(NiL));
UNREACHABLE();
}
mask = umask(0);
if (!mflag)
{

View file

@ -116,13 +116,16 @@ b_mktemp(int argc, char** argv, Shbltin_t* context)
break;
case '?':
error(ERROR_usage(2), "%s", opt_info.arg);
break;
UNREACHABLE();
}
break;
}
argv += opt_info.index;
if (error_info.errors || (pfx = *argv++) && *argv)
{
error(ERROR_usage(2), "%s", optusage(NiL));
UNREACHABLE();
}
mask = umask(0);
if (!mode)
mode = (fdp ? (S_IRUSR|S_IWUSR) : S_IRWXU) & ~mask;

View file

@ -199,13 +199,16 @@ b_paste(int argc, char** argv, Shbltin_t* context)
break;
case '?':
error(ERROR_usage(2), "%s", opt_info.arg);
break;
UNREACHABLE();
}
break;
}
argv += opt_info.index;
if(error_info.errors)
{
error(ERROR_usage(2),"%s", optusage(NiL));
UNREACHABLE();
}
if(!delim || !*delim)
{
delim = defdelim;
@ -213,7 +216,10 @@ b_paste(int argc, char** argv, Shbltin_t* context)
delim[1] = 0;
}
if (!(delim = strdup(delim)))
{
error(ERROR_system(1), "out of memory");
UNREACHABLE();
}
dlen = dsiz = stresc(delim);
mp = 0;
if (mbwide())
@ -232,6 +238,7 @@ b_paste(int argc, char** argv, Shbltin_t* context)
{
free(delim);
error(ERROR_system(1), "out of memory");
UNREACHABLE();
}
cp = delim;
dlen = 0;
@ -254,7 +261,10 @@ b_paste(int argc, char** argv, Shbltin_t* context)
if(!sflag)
{
if (!(streams = (Sfio_t**)stakalloc(n*sizeof(Sfio_t*))))
{
error(ERROR_exit(1), "out of memory");
UNREACHABLE();
}
n = 0;
}
do

View file

@ -252,13 +252,16 @@ b_pathchk(int argc, char** argv, Shbltin_t* context)
break;
case '?':
error(ERROR_usage(2), "%s", opt_info.arg);
break;
UNREACHABLE();
}
break;
}
argv += opt_info.index;
if (!*argv || error_info.errors)
{
error(ERROR_usage(2),"%s", optusage(NiL));
UNREACHABLE();
}
while (s = *argv++)
pathchk(s, mode);
return error_info.errors != 0;

View file

@ -105,8 +105,8 @@ b_pids(int argc, char** argv, Shbltin_t* context)
format = opt_info.arg;
continue;
case '?':
error(ERROR_USAGE|4, "%s", opt_info.arg);
break;
error(ERROR_usage(2), "%s", opt_info.arg);
UNREACHABLE();
case ':':
error(2, "%s", opt_info.arg);
break;
@ -115,7 +115,10 @@ b_pids(int argc, char** argv, Shbltin_t* context)
}
argv += opt_info.index;
if (error_info.errors || *argv)
error(ERROR_USAGE|4, "%s", optusage(NiL));
{
error(ERROR_usage(2), "%s", optusage(NiL));
UNREACHABLE();
}
if (!format)
format = FORMAT;
sfkeyprintf(sfstdout, format, format, key, NiL);

View file

@ -134,13 +134,16 @@ b_rev(int argc, register char** argv, Shbltin_t* context)
break;
case '?':
error(ERROR_usage(2), "%s", opt_info.arg);
break;
UNREACHABLE();
}
break;
}
argv += opt_info.index;
if(error_info.errors)
{
error(ERROR_usage(2),"%s",optusage((char*)0));
UNREACHABLE();
}
n=0;
if(cp = *argv)
argv++;
@ -161,7 +164,10 @@ b_rev(int argc, register char** argv, Shbltin_t* context)
if(fp!=sfstdin)
sfclose(fp);
if(line < 0)
{
error(ERROR_system(1),"write failed");
UNREACHABLE();
}
}
while(cp= *argv++);
return(n);

View file

@ -366,8 +366,8 @@ b_rm(int argc, register char** argv, Shbltin_t* context)
state.verbose = 1;
continue;
case '?':
error(ERROR_USAGE|4, "%s", opt_info.arg);
break;
error(ERROR_usage(2), "%s", opt_info.arg);
UNREACHABLE();
case ':':
error(2, "%s", opt_info.arg);
break;
@ -378,7 +378,10 @@ b_rm(int argc, register char** argv, Shbltin_t* context)
if (*argv && streq(*argv, "-") && !streq(*(argv - 1), "--"))
argv++;
if (error_info.errors || !*argv && !state.force)
error(ERROR_USAGE|4, "%s", optusage(NiL));
{
error(ERROR_usage(2), "%s", optusage(NiL));
UNREACHABLE();
}
if (!*argv)
return 0;

View file

@ -82,13 +82,16 @@ b_rmdir(int argc, char** argv, Shbltin_t* context)
break;
case '?':
error(ERROR_usage(2), "%s", opt_info.arg);
break;
UNREACHABLE();
}
break;
}
argv += opt_info.index;
if (error_info.errors || !*argv)
{
error(ERROR_usage(2), "%s", optusage(NiL));
UNREACHABLE();
}
if (!pflag)
sflag = 0;
while (dir = *argv++)

View file

@ -645,14 +645,23 @@ static void set(char *argv[], struct termios *sp)
off=1;
}
if(!(tp=lookup(cp)) || (off && (tp->type!=BIT) && (tp->type!=TABS)))
{
error(ERROR_exit(1),"%s: unknown mode",cp);
UNREACHABLE();
}
switch(tp->type)
{
case CHAR:
if(off)
{
error(ERROR_exit(1),"%s: unknown mode",cp);
UNREACHABLE();
}
if(!*argv)
{
error(ERROR_exit(1),"missing argument to %s",cp);
UNREACHABLE();
}
c = gettchar(*argv++);
if(c>=0)
sp->c_cc[tp->mask] = c;
@ -697,7 +706,10 @@ static void set(char *argv[], struct termios *sp)
struct winsize win;
int n;
if(ioctl(0,TIOCGWINSZ,&win)<0)
{
error(ERROR_system(1),"cannot set %s",tp->name);
UNREACHABLE();
}
if(!(cp= *argv))
{
sfprintf(sfstdout,"%d\n",tp->mask?win.ws_col:win.ws_row);
@ -706,13 +718,19 @@ static void set(char *argv[], struct termios *sp)
argv++;
n=strtol(cp,&cp,10);
if(*cp)
{
error(ERROR_system(1),"%d: invalid number of %s",argv[-1],tp->name);
UNREACHABLE();
}
if(tp->mask)
win.ws_col = n;
else
win.ws_row = n;
if(ioctl(0,TIOCSWINSZ,&win)<0)
{
error(ERROR_system(1),"cannot set %s",tp->name);
UNREACHABLE();
}
break;
}
#endif
@ -727,11 +745,15 @@ static void set(char *argv[], struct termios *sp)
break;
}
error(ERROR_exit(1), "%s: missing numeric argument", tp->name);
UNREACHABLE();
}
argv++;
c = (int)strtol(cp, &ep, 10);
if (*ep)
{
error(ERROR_exit(1), "%s: %s: numeric argument expected", tp->name, cp);
UNREACHABLE();
}
switch (tp->field)
{
#if _mem_c_line_termios
@ -748,7 +770,10 @@ static void set(char *argv[], struct termios *sp)
cfsetospeed(sp, c);
}
else
{
error(ERROR_exit(1), "%s: %s: invalid speed", tp->name, cp);
UNREACHABLE();
}
break;
case T_CHAR:
sp->c_cc[tp->mask] = c;
@ -941,19 +966,28 @@ b_stty(int argc, char** argv, Shbltin_t* context)
if (!opt_info.offset)
error(2, "%s", opt_info.arg);
else if (!(tp = lookup(argv[opt_info.index]+1)) || (tp->type != BIT && tp->type != TABS))
{
error(ERROR_exit(1), "%s: unknown mode", argv[opt_info.index]);
UNREACHABLE();
}
break;
case '?':
error(ERROR_usage(2), "%s", opt_info.arg);
break;
UNREACHABLE();
}
break;
}
argv += opt_info.index;
if (error_info.errors || (flags && *argv) || (flags&(flags-1)))
{
error(ERROR_usage(2), "%s", optusage(NiL));
UNREACHABLE();
}
if (tcgetattr(fd, &tty) < 0)
{
error(ERROR_system(1), "not a tty");
UNREACHABLE();
}
if (flags & T_FLAG)
sfprintf(sfstdout, "%d\n", tcgetpgrp(0));
else if (*argv)
@ -963,7 +997,10 @@ b_stty(int argc, char** argv, Shbltin_t* context)
else
set(argv, &tty);
if (tcsetattr(0, TCSANOW, &tty) < 0)
{
error(ERROR_system(1), "cannot set tty");
UNREACHABLE();
}
}
else
output(&tty, flags);

View file

@ -63,17 +63,21 @@ b_sync(int argc, char** argv, Shbltin_t* context)
break;
case '?':
error(ERROR_usage(2), "%s", opt_info.arg);
break;
UNREACHABLE();
}
break;
}
argv += opt_info.index;
if (error_info.errors || *argv)
{
error(ERROR_usage(2), "%s", optusage(NiL));
UNREACHABLE();
}
#if _lib_sync
sync();
return 0;
#else
error(ERROR_usage(2), "failed -- the native system does not provide a sync(2) call");
UNREACHABLE();
#endif
return 0;
}

View file

@ -515,7 +515,10 @@ b_tail(int argc, char** argv, Shbltin_t* context)
flags |= TIMEOUT;
timeout = strelapsed(opt_info.arg, &s, 1);
if (*s)
{
error(ERROR_exit(1), "%s: invalid elapsed time [%s]", opt_info.arg, s);
UNREACHABLE();
}
continue;
case 'v':
flags |= VERBOSE;
@ -569,7 +572,7 @@ b_tail(int argc, char** argv, Shbltin_t* context)
continue;
case '?':
error(ERROR_usage(2), "%s", opt_info.arg);
break;
UNREACHABLE();
}
break;
}
@ -611,7 +614,10 @@ b_tail(int argc, char** argv, Shbltin_t* context)
if (flags & FOLLOW)
{
if (!(fp = (Tail_t*)stakalloc(argc * sizeof(Tail_t))))
{
error(ERROR_system(1), "out of memory");
UNREACHABLE();
}
files = 0;
s = *argv;
do
@ -718,7 +724,10 @@ b_tail(int argc, char** argv, Shbltin_t* context)
fp = fp->next;
}
if (sfsync(sfstdout))
{
error(ERROR_system(1), "write error");
UNREACHABLE();
}
}
done:
for (fp = files; fp; fp = fp->next)

View file

@ -149,12 +149,15 @@ b_tee(int argc, register char** argv, Shbltin_t* context)
break;
case '?':
error(ERROR_usage(2), "%s", opt_info.arg);
break;
UNREACHABLE();
}
break;
}
if (error_info.errors)
{
error(ERROR_usage(2), "%s", optusage(NiL));
UNREACHABLE();
}
argv += opt_info.index;
argc -= opt_info.index;
#if _ANCIENT_BSD_COMPATIBILITY

View file

@ -79,12 +79,15 @@ b_tty(int argc, char** argv, Shbltin_t* context)
break;
case '?':
error(ERROR_usage(2), "%s", opt_info.arg);
break;
UNREACHABLE();
}
break;
}
if(error_info.errors)
{
error(ERROR_usage(2), "%s", optusage(NiL));
UNREACHABLE();
}
if(!(tty=ttyname(0)))
{
tty = ERROR_translate(0, 0, 0, "not a tty");

View file

@ -337,13 +337,16 @@ b_uname(int argc, char** argv, Shbltin_t* context)
}
case '?':
error(ERROR_usage(2), "%s", opt_info.arg);
break;
UNREACHABLE();
}
break;
}
argv += opt_info.index;
if (error_info.errors || *argv && (flags || sethost) || sethost && flags)
{
error(ERROR_usage(2), "%s", optusage(NiL));
UNREACHABLE();
}
if (sethost)
{
#if _lib_sethostname
@ -356,6 +359,7 @@ b_uname(int argc, char** argv, Shbltin_t* context)
#endif
#endif
error(ERROR_system(1), "%s: cannot set host name", sethost);
UNREACHABLE();
}
else if (list)
astconflist(sfstdout, NiL, ASTCONF_base|ASTCONF_defined|ASTCONF_lower|ASTCONF_quote|ASTCONF_matchcall, "CS|SI");
@ -381,7 +385,10 @@ b_uname(int argc, char** argv, Shbltin_t* context)
flags = OPT_system;
memzero(&ut, sizeof(ut));
if (uname(&ut) < 0)
{
error(ERROR_usage(2), "information unavailable");
UNREACHABLE();
}
output(OPT_system, ut.sysname, "sysname");
if (flags & OPT_nodename)
{

View file

@ -303,7 +303,7 @@ b_uniq(int argc, char** argv, Shbltin_t* context)
break;
case '?':
error(ERROR_usage(2), "%s", opt_info.arg);
break;
UNREACHABLE();
}
break;
}
@ -311,11 +311,17 @@ b_uniq(int argc, char** argv, Shbltin_t* context)
if(all && (mode&C_FLAG))
error(2, "-c and -D are mutually exclusive");
if(error_info.errors)
{
error(ERROR_usage(2), "%s", optusage(NiL));
UNREACHABLE();
}
if((cp = *argv) && (argv++,!streq(cp,"-")))
{
if(!(fpin = sfopen(NiL,cp,"r")))
{
error(ERROR_system(1),"%s: cannot open",cp);
UNREACHABLE();
}
}
else
fpin = sfstdin;
@ -323,7 +329,10 @@ b_uniq(int argc, char** argv, Shbltin_t* context)
{
argv++;
if(!(fpout = sfopen(NiL,cp,"w")))
{
error(ERROR_system(1),"%s: cannot create",cp);
UNREACHABLE();
}
}
else
fpout = sfstdout;
@ -331,6 +340,7 @@ b_uniq(int argc, char** argv, Shbltin_t* context)
{
error(2, "too many arguments");
error(ERROR_usage(2), "%s", optusage(NiL));
UNREACHABLE();
}
error_info.errors = uniq(fpin,fpout,fields,chars,width,mode,all,compare);
if(fpin!=sfstdin)

View file

@ -163,8 +163,8 @@ b_vmstate(int argc, char** argv, Shbltin_t* context)
state.format = opt_info.arg;
continue;
case '?':
error(ERROR_USAGE|4, "%s", opt_info.arg);
break;
error(ERROR_usage(2), "%s", opt_info.arg);
UNREACHABLE();
case ':':
error(2, "%s", opt_info.arg);
break;
@ -173,7 +173,10 @@ b_vmstate(int argc, char** argv, Shbltin_t* context)
}
argv += opt_info.index;
if (error_info.errors || *argv)
error(ERROR_USAGE|4, "%s", optusage(NiL));
{
error(ERROR_usage(2), "%s", optusage(NiL));
UNREACHABLE();
}
if (!state.format)
state.format = FORMAT;

View file

@ -129,13 +129,16 @@ b_wc(int argc,register char **argv, Shbltin_t* context)
break;
case '?':
error(ERROR_usage(2), "%s", opt_info.arg);
break;
UNREACHABLE();
}
break;
}
argv += opt_info.index;
if (error_info.errors)
{
error(ERROR_usage(2), "%s", optusage(NiL));
UNREACHABLE();
}
if (mode&WC_MBYTE)
{
if (mode&WC_CHARS)

View file

@ -201,7 +201,7 @@ vercmp(FTSENT* const* ap, FTSENT* const* bp)
if (!*b++)
return 1;
}
/*NOTREACHED*/
UNREACHABLE();
}
/*