Deleted Added
full compact
file.c (179835) file.c (206043)
1/*
2 * FreeBSD install - a package for the installation and maintainance
3 * of non-core utilities.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 5 unchanged lines hidden (view full) ---

14 * Jordan K. Hubbard
15 * 18 July 1993
16 *
17 * Miscellaneous file access utilities.
18 *
19 */
20
21#include <sys/cdefs.h>
1/*
2 * FreeBSD install - a package for the installation and maintainance
3 * of non-core utilities.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 5 unchanged lines hidden (view full) ---

14 * Jordan K. Hubbard
15 * 18 July 1993
16 *
17 * Miscellaneous file access utilities.
18 *
19 */
20
21#include <sys/cdefs.h>
22__FBSDID("$FreeBSD: head/usr.sbin/pkg_install/lib/file.c 179835 2008-06-16 23:41:11Z flz $");
22__FBSDID("$FreeBSD: head/usr.sbin/pkg_install/lib/file.c 206043 2010-04-01 14:27:29Z flz $");
23
24#include "lib.h"
25#include <err.h>
26#include <pwd.h>
27#include <time.h>
28#include <sys/wait.h>
29
30/* Quick check to see if a file exists */
31Boolean
32fexists(const char *fname)
33{
23
24#include "lib.h"
25#include <err.h>
26#include <pwd.h>
27#include <time.h>
28#include <sys/wait.h>
29
30/* Quick check to see if a file exists */
31Boolean
32fexists(const char *fname)
33{
34 struct stat dummy;
35 if (!lstat(fname, &dummy))
36 return TRUE;
37 return FALSE;
34 int fd;
35
36 if ((fd = open(fname, O_RDONLY)) == -1)
37 return FALSE;
38
39 close(fd);
40 return TRUE;
38}
39
40/* Quick check to see if something is a directory or symlink to a directory */
41Boolean
42isdir(const char *fname)
43{
44 struct stat sb;
45

--- 228 unchanged lines hidden (view full) ---

274 snprintf(cmd, FILENAME_MAX, "/bin/cp -r %s/%s %s", dir, fname, to);
275 if (vsystem(cmd)) {
276 cleanup(0);
277 errx(2, "%s: could not perform '%s'", __func__, cmd);
278 }
279}
280
281void
41}
42
43/* Quick check to see if something is a directory or symlink to a directory */
44Boolean
45isdir(const char *fname)
46{
47 struct stat sb;
48

--- 228 unchanged lines hidden (view full) ---

277 snprintf(cmd, FILENAME_MAX, "/bin/cp -r %s/%s %s", dir, fname, to);
278 if (vsystem(cmd)) {
279 cleanup(0);
280 errx(2, "%s: could not perform '%s'", __func__, cmd);
281 }
282}
283
284void
282move_file(const char *dir, const char *fname, const char *to)
285move_file(const char *dir, const char *fname, const char *tdir)
283{
286{
284 char cmd[FILENAME_MAX];
287 char from[FILENAME_MAX];
288 char to[FILENAME_MAX];
285
286 if (fname[0] == '/')
289
290 if (fname[0] == '/')
287 snprintf(cmd, FILENAME_MAX, "/bin/mv %s %s", fname, to);
291 strncpy(from, fname, FILENAME_MAX);
288 else
292 else
289 snprintf(cmd, FILENAME_MAX, "/bin/mv %s/%s %s", dir, fname, to);
290 if (vsystem(cmd)) {
291 cleanup(0);
292 errx(2, "%s: could not perform '%s'", __func__, cmd);
293 snprintf(from, FILENAME_MAX, "%s/%s", dir, fname);
294
295 snprintf(to, FILENAME_MAX, "%s/%s", tdir, fname);
296
297 if (rename(from, to) == -1) {
298 if (vsystem("/bin/mv %s %s", from, to)) {
299 cleanup(0);
300 errx(2, "%s: could not move '%s' to '%s'", __func__, from, to);
301 }
293 }
294}
295
296/*
297 * Copy a hierarchy (possibly from dir) to the current directory, or
298 * if "to" is TRUE, from the current directory to a location someplace
299 * else.
300 *

--- 127 unchanged lines hidden ---
302 }
303}
304
305/*
306 * Copy a hierarchy (possibly from dir) to the current directory, or
307 * if "to" is TRUE, from the current directory to a location someplace
308 * else.
309 *

--- 127 unchanged lines hidden ---