Deleted Added
full compact
file.c (93520) file.c (96388)
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 93520 2002-04-01 09:39:07Z obrien $");
22__FBSDID("$FreeBSD: head/usr.sbin/pkg_install/lib/file.c 96388 2002-05-11 03:48:49Z alfred $");
23
24#include "lib.h"
25#include <err.h>
26#include <fetch.h>
27#include <pwd.h>
28#include <time.h>
29#include <sys/wait.h>
30

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

295fileGetContents(const char *fname)
296{
297 char *contents;
298 struct stat sb;
299 int fd;
300
301 if (stat(fname, &sb) == FAIL) {
302 cleanup(0);
23
24#include "lib.h"
25#include <err.h>
26#include <fetch.h>
27#include <pwd.h>
28#include <time.h>
29#include <sys/wait.h>
30

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

295fileGetContents(const char *fname)
296{
297 char *contents;
298 struct stat sb;
299 int fd;
300
301 if (stat(fname, &sb) == FAIL) {
302 cleanup(0);
303 errx(2, __FUNCTION__ ": can't stat '%s'", fname);
303 errx(2, "%s: can't stat '%s'", __FUNCTION__, fname);
304 }
305
306 contents = (char *)malloc(sb.st_size + 1);
307 fd = open(fname, O_RDONLY, 0);
308 if (fd == FAIL) {
309 cleanup(0);
304 }
305
306 contents = (char *)malloc(sb.st_size + 1);
307 fd = open(fname, O_RDONLY, 0);
308 if (fd == FAIL) {
309 cleanup(0);
310 errx(2, __FUNCTION__ ": unable to open '%s' for reading", fname);
310 errx(2, "%s: unable to open '%s' for reading", __FUNCTION__, fname);
311 }
312 if (read(fd, contents, sb.st_size) != sb.st_size) {
313 cleanup(0);
311 }
312 if (read(fd, contents, sb.st_size) != sb.st_size) {
313 cleanup(0);
314 errx(2, __FUNCTION__ ": short read on '%s' - did not get %qd bytes",
314 errx(2, "%s: short read on '%s' - did not get %qd bytes", __FUNCTION__,
315 fname, (long long)sb.st_size);
316 }
317 close(fd);
318 contents[sb.st_size] = '\0';
319 return contents;
320}
321
322/*

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

359write_file(const char *name, const char *str)
360{
361 FILE *fp;
362 size_t len;
363
364 fp = fopen(name, "w");
365 if (!fp) {
366 cleanup(0);
315 fname, (long long)sb.st_size);
316 }
317 close(fd);
318 contents[sb.st_size] = '\0';
319 return contents;
320}
321
322/*

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

359write_file(const char *name, const char *str)
360{
361 FILE *fp;
362 size_t len;
363
364 fp = fopen(name, "w");
365 if (!fp) {
366 cleanup(0);
367 errx(2, __FUNCTION__ ": cannot fopen '%s' for writing", name);
367 errx(2, "%s: cannot fopen '%s' for writing", __FUNCTION__, name);
368 }
369 len = strlen(str);
370 if (fwrite(str, 1, len, fp) != len) {
371 cleanup(0);
368 }
369 len = strlen(str);
370 if (fwrite(str, 1, len, fp) != len) {
371 cleanup(0);
372 errx(2, __FUNCTION__ ": short fwrite on '%s', tried to write %ld bytes", name, (long)len);
372 errx(2, "%s: short fwrite on '%s', tried to write %ld bytes",
373 __FUNCTION__, name, (long)len);
373 }
374 if (fclose(fp)) {
375 cleanup(0);
374 }
375 if (fclose(fp)) {
376 cleanup(0);
376 errx(2, __FUNCTION__ ": failure to fclose '%s'", name);
377 errx(2, "%s: failure to fclose '%s'", __FUNCTION__, name);
377 }
378}
379
380void
381copy_file(const char *dir, const char *fname, const char *to)
382{
383 char cmd[FILENAME_MAX];
384
385 if (fname[0] == '/')
386 snprintf(cmd, FILENAME_MAX, "cp -r %s %s", fname, to);
387 else
388 snprintf(cmd, FILENAME_MAX, "cp -r %s/%s %s", dir, fname, to);
389 if (vsystem(cmd)) {
390 cleanup(0);
378 }
379}
380
381void
382copy_file(const char *dir, const char *fname, const char *to)
383{
384 char cmd[FILENAME_MAX];
385
386 if (fname[0] == '/')
387 snprintf(cmd, FILENAME_MAX, "cp -r %s %s", fname, to);
388 else
389 snprintf(cmd, FILENAME_MAX, "cp -r %s/%s %s", dir, fname, to);
390 if (vsystem(cmd)) {
391 cleanup(0);
391 errx(2, __FUNCTION__ ": could not perform '%s'", cmd);
392 errx(2, "%s: could not perform '%s'", __FUNCTION__, cmd);
392 }
393}
394
395void
396move_file(const char *dir, const char *fname, const char *to)
397{
398 char cmd[FILENAME_MAX];
399
400 if (fname[0] == '/')
401 snprintf(cmd, FILENAME_MAX, "mv %s %s", fname, to);
402 else
403 snprintf(cmd, FILENAME_MAX, "mv %s/%s %s", dir, fname, to);
404 if (vsystem(cmd)) {
405 cleanup(0);
393 }
394}
395
396void
397move_file(const char *dir, const char *fname, const char *to)
398{
399 char cmd[FILENAME_MAX];
400
401 if (fname[0] == '/')
402 snprintf(cmd, FILENAME_MAX, "mv %s %s", fname, to);
403 else
404 snprintf(cmd, FILENAME_MAX, "mv %s/%s %s", dir, fname, to);
405 if (vsystem(cmd)) {
406 cleanup(0);
406 errx(2, __FUNCTION__ ": could not perform '%s'", cmd);
407 errx(2, "%s: could not perform '%s'", __FUNCTION__, cmd);
407 }
408}
409
410/*
411 * Copy a hierarchy (possibly from dir) to the current directory, or
412 * if "to" is TRUE, from the current directory to a location someplace
413 * else.
414 *

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

430 else
431 snprintf(cmd, FILENAME_MAX * 3, "tar cf - %s | tar xpf - -C %s",
432 fname, dir);
433#ifdef DEBUG
434 printf("Using '%s' to copy trees.\n", cmd);
435#endif
436 if (system(cmd)) {
437 cleanup(0);
408 }
409}
410
411/*
412 * Copy a hierarchy (possibly from dir) to the current directory, or
413 * if "to" is TRUE, from the current directory to a location someplace
414 * else.
415 *

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

431 else
432 snprintf(cmd, FILENAME_MAX * 3, "tar cf - %s | tar xpf - -C %s",
433 fname, dir);
434#ifdef DEBUG
435 printf("Using '%s' to copy trees.\n", cmd);
436#endif
437 if (system(cmd)) {
438 cleanup(0);
438 errx(2, __FUNCTION__ ": could not perform '%s'", cmd);
439 errx(2, "%s: could not perform '%s'", __FUNCTION__, cmd);
439 }
440}
441
442/* Unpack a tar file */
443int
444unpack(const char *pkg, const char *flist)
445{
446 char args[10], suff[80], *cp;

--- 87 unchanged lines hidden ---
440 }
441}
442
443/* Unpack a tar file */
444int
445unpack(const char *pkg, const char *flist)
446{
447 char args[10], suff[80], *cp;

--- 87 unchanged lines hidden ---