X-Git-Url: https://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=progs%2Ftoe.c;h=6f45992f712416ceb837b6d7a4dbfb1194685ab9;hp=38b85cb362ed0918fd1975b29fabdce782a21c11;hb=d448186ac240901c6976dc74c260f052d3ed53e4;hpb=8144a95f5729b46a1ad4f4c3c4ba29800304e4c0 diff --git a/progs/toe.c b/progs/toe.c index 38b85cb3..6f45992f 100644 --- a/progs/toe.c +++ b/progs/toe.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. * + * Copyright (c) 1998-2008,2010 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -44,7 +44,7 @@ #include #endif -MODULE_ID("$Id: toe.c,v 1.48 2008/01/05 20:41:26 tom Exp $") +MODULE_ID("$Id: toe.c,v 1.52 2010/05/01 22:04:08 tom Exp $") #define isDotname(name) (!strcmp(name, ".") || !strcmp(name, "..")) @@ -61,6 +61,13 @@ ExitProgram(int code) } #endif +static void +failed(const char *msg) +{ + perror(msg); + ExitProgram(EXIT_FAILURE); +} + #if USE_HASHED_DB static bool make_db_name(char *dst, const char *src, unsigned limit) @@ -163,6 +170,7 @@ typelist(int eargc, char *eargv[], for (i = 0; i < eargc; i++) { #if USE_DATABASE if (_nc_is_dir_path(eargv[i])) { + char *cwd_buf = 0; DIR *termdir; DIRENT *subdir; @@ -177,20 +185,30 @@ typelist(int eargc, char *eargv[], while ((subdir = readdir(termdir)) != 0) { size_t len = NAMLEN(subdir); - char buf[PATH_MAX]; + size_t cwd_len = len + strlen(eargv[i]) + 3; char name_1[PATH_MAX]; DIR *entrydir; DIRENT *entry; + cwd_buf = typeRealloc(char, cwd_len, cwd_buf); + if (cwd_buf == 0) + failed("realloc cwd_buf"); + + assert(cwd_buf != 0); + strncpy(name_1, subdir->d_name, len)[len] = '\0'; if (isDotname(name_1)) continue; - (void) sprintf(buf, "%s/%s/", eargv[i], name_1); - if (chdir(buf) != 0) + (void) sprintf(cwd_buf, "%s/%.*s/", eargv[i], (int) len, name_1); + if (chdir(cwd_buf) != 0) continue; entrydir = opendir("."); + if (entrydir == 0) { + perror(cwd_buf); + continue; + } while ((entry = readdir(entrydir)) != 0) { char name_2[PATH_MAX]; TERMTYPE lterm; @@ -222,6 +240,8 @@ typelist(int eargc, char *eargv[], closedir(entrydir); } closedir(termdir); + if (cwd_buf != 0) + free(cwd_buf); } #if USE_HASHED_DB else { @@ -317,7 +337,7 @@ main(int argc, char *argv[]) bool invert_dependencies = FALSE; bool header = FALSE; char *report_file = 0; - int i; + unsigned i; int code; int this_opt, last_opt = '?'; int v_opt = 0; @@ -386,7 +406,7 @@ main(int argc, char *argv[]) for_entry_list(qp) { if (qp->nuses) { - int j; + unsigned j; (void) printf("%s:", _nc_first_name(qp->tterm.term_names)); for (j = 0; j < qp->nuses; j++) @@ -467,6 +487,10 @@ main(int argc, char *argv[]) } if (!pass) { eargv = typeCalloc(char *, count + 1); + if (eargv == 0) + failed("realloc eargv"); + + assert(eargv != 0); } else { code = typelist((int) count, eargv, header, deschook); while (count-- > 0)