1 /* This file is part of GDBM, the GNU data base manager.
2 Copyright (C) 1990, 1991, 1993, 2007, 2011, 2013 Free Software Foundation,
5 GDBM is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3, or (at your option)
10 GDBM is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GDBM. If not, see <http://www.gnu.org/licenses/>. */
22 mkfilename (const char *dir, const char *file, const char *suf)
25 size_t dirlen = strlen (dir);
26 size_t suflen = suf ? strlen (suf) : 0;
27 size_t fillen = strlen (file);
30 while (dirlen > 0 && dir[dirlen-1] == '/')
33 len = dirlen + (dir[0] ? 1 : 0) + fillen + suflen;
34 tmp = emalloc (len + 1);
35 memcpy (tmp, dir, dirlen);
38 memcpy (tmp + dirlen, file, fillen);
40 memcpy (tmp + dirlen + fillen, suf, suflen);
51 size_t len = strcspn (p, "/");
55 pw = getpwuid (getuid ());
58 char *user = emalloc (len + 1);
60 memcpy (user, p, len);
66 return mkfilename (pw->pw_dir, p + len + 1, NULL);
72 vgetyn (const char *prompt, va_list ap)
82 if (c == ' ' || c == '\t')
99 fprintf (stdout, "%s\n", _("Please, reply 'y' or 'n'"));
106 vfprintf (stdout, prompt, ap);
107 fprintf (stdout, " [y/n]?");
112 } while ((c = getchar ()) != EOF);
117 getyn (const char *prompt, ...)
122 va_start (ap, prompt);
123 rc = vgetyn (prompt, ap);