Annotation of src/usr.bin/gzsig/util.c, Revision 1.4
1.4 ! tobias 1: /* $OpenBSD: util.c,v 1.3 2013/03/10 10:34:33 tobias Exp $ */
1.1 marius 2:
3: /*
4: * util.c
5: *
6: * Copyright (c) 2001 Dug Song <dugsong@arbor.net>
7: * Copyright (c) 2001 Arbor Networks, Inc.
8: *
9: * Redistribution and use in source and binary forms, with or without
10: * modification, are permitted provided that the following conditions
11: * are met:
12: *
13: * 1. Redistributions of source code must retain the above copyright
14: * notice, this list of conditions and the following disclaimer.
15: * 2. Redistributions in binary form must reproduce the above copyright
16: * notice, this list of conditions and the following disclaimer in the
17: * documentation and/or other materials provided with the distribution.
18: * 3. The names of the copyright holders may not be used to endorse or
19: * promote products derived from this software without specific
20: * prior written permission.
21: *
22: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
23: * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
24: * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
25: * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
28: * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29: * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
30: * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
31: * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32: *
1.2 marius 33: * $Vendor: util.c,v 1.2 2005/04/01 16:47:31 dugsong Exp $
1.1 marius 34: */
35:
36: #include <sys/types.h>
37: #include <sys/stat.h>
38:
39: #include <errno.h>
40: #include <stdio.h>
41: #include <stdlib.h>
42: #include <stdarg.h>
43: #include <string.h>
44: #include <unistd.h>
45:
46: #include "util.h"
47:
48: int
1.3 tobias 49: copy_permissions(int srcfd, int dstfd)
1.1 marius 50: {
51: struct stat st;
52:
1.3 tobias 53: if (fstat(srcfd, &st) < 0)
1.1 marius 54: return (-1);
55:
1.3 tobias 56: if (fchown(dstfd, st.st_uid, st.st_gid) < 0)
1.1 marius 57: return (-1);
58:
1.3 tobias 59: if (fchmod(dstfd, st.st_mode) < 0)
1.1 marius 60: return (-1);
61:
1.4 ! tobias 62: return (0);
! 63: }
! 64:
! 65: int
! 66: skip_string(FILE *fin)
! 67: {
! 68: int c;
! 69:
! 70: while ((c = getc(fin)) != '\0')
! 71: if (c == EOF)
! 72: return (-1);
1.1 marius 73: return (0);
74: }
75:
76: void
77: fatal(int status, const char *fmt, ...)
78: {
79: va_list ap;
80:
81: va_start(ap, fmt);
82: vfprintf(stderr, fmt, ap);
83: va_end(ap);
84:
85: fprintf(stderr, "\n");
86:
87: exit(status);
88: }