Deleted Added
full compact
file.c (96388) file.c (96392)
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 96388 2002-05-11 03:48:49Z alfred $");
22__FBSDID("$FreeBSD: head/usr.sbin/pkg_install/lib/file.c 96392 2002-05-11 04:17:55Z 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, "%s: can't stat '%s'", __FUNCTION__, fname);
303 errx(2, "%s: can't stat '%s'", __func__, 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, "%s: unable to open '%s' for reading", __FUNCTION__, fname);
310 errx(2, "%s: unable to open '%s' for reading", __func__, 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, "%s: short read on '%s' - did not get %qd bytes", __FUNCTION__,
314 errx(2, "%s: short read on '%s' - did not get %qd bytes", __func__,
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, "%s: cannot fopen '%s' for writing", __FUNCTION__, name);
367 errx(2, "%s: cannot fopen '%s' for writing", __func__, name);
368 }
369 len = strlen(str);
370 if (fwrite(str, 1, len, fp) != len) {
371 cleanup(0);
372 errx(2, "%s: short fwrite on '%s', tried to write %ld bytes",
368 }
369 len = strlen(str);
370 if (fwrite(str, 1, len, fp) != len) {
371 cleanup(0);
372 errx(2, "%s: short fwrite on '%s', tried to write %ld bytes",
373 __FUNCTION__, name, (long)len);
373 __func__, name, (long)len);
374 }
375 if (fclose(fp)) {
376 cleanup(0);
374 }
375 if (fclose(fp)) {
376 cleanup(0);
377 errx(2, "%s: failure to fclose '%s'", __FUNCTION__, name);
377 errx(2, "%s: failure to fclose '%s'", __func__, name);
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);
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);
392 errx(2, "%s: could not perform '%s'", __FUNCTION__, cmd);
392 errx(2, "%s: could not perform '%s'", __func__, cmd);
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);
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);
407 errx(2, "%s: could not perform '%s'", __FUNCTION__, cmd);
407 errx(2, "%s: could not perform '%s'", __func__, cmd);
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);
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);
439 errx(2, "%s: could not perform '%s'", __FUNCTION__, cmd);
439 errx(2, "%s: could not perform '%s'", __func__, cmd);
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 ---
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 ---