X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/f67e3671c985ad8095dc6fcc8be7ba6dd25cdf63..9b706433f:/uip/prompter.c?ds=sidebyside diff --git a/uip/prompter.c b/uip/prompter.c index 563da058..37f5960b 100644 --- a/uip/prompter.c +++ b/uip/prompter.c @@ -10,8 +10,6 @@ #include #include #include -#include -#include #include #include @@ -74,19 +72,13 @@ main (int argc, char **argv) int doteof = 0, fdi, fdo, i, state; char *cp, *drft = NULL, *erasep = NULL; char *killp = NULL, name[NAMESZ], field[BUFSIZ]; - char buffer[BUFSIZ], tmpfil[BUFSIZ]; + char buffer[BUFSIZ]; char **arguments, **argp; FILE *in, *out; - char *tfile = NULL; + char *tmpfil; m_getfld_state_t gstate = 0; -#ifdef LOCALE - setlocale(LC_ALL, ""); -#endif - invo_name = r1bindex (argv[0], '/'); - - /* read user profile/context */ - context_read(); + if (nmh_init(argv[0], 1)) { return 1; } arguments = getarguments (invo_name, argc, argv, 1); argp = arguments; @@ -156,10 +148,9 @@ main (int argc, char **argv) if ((in = fopen (drft, "r")) == NULL) adios (drft, "unable to open"); - tfile = m_mktemp2(NULL, invo_name, NULL, &out); - if (tfile == NULL) adios("prompter", "unable to create temporary file"); - chmod (tmpfil, 0600); - strncpy (tmpfil, tfile, sizeof(tmpfil)); + if ((tmpfil = m_mktemp2(NULL, invo_name, NULL, &out)) == NULL) { + adios(NULL, "unable to create temporary file in %s", get_temp_dir()); + } /* * Are we changing the kill or erase character? @@ -236,7 +227,7 @@ abort: if (killp || erasep) { tcsetattr(0, TCSADRAIN, &tio); } - unlink (tmpfil); + (void) m_unlink (tmpfil); done (1); } if (i != 0 || (field[0] != '\n' && field[0] != 0)) { @@ -325,7 +316,7 @@ abort: cpydata (fdi, fdo, tmpfil, drft); close (fdi); close (fdo); - unlink (tmpfil); + (void) m_unlink (tmpfil); context_save (); /* save the context file */ done (0);