Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | /* |
2 | * ========== Copyright Header Begin ========================================== | |
3 | * | |
4 | * OpenSPARC T2 Processor File: fileutil.c | |
5 | * Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved. | |
6 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES. | |
7 | * | |
8 | * The above named program is free software; you can redistribute it and/or | |
9 | * modify it under the terms of the GNU General Public | |
10 | * License version 2 as published by the Free Software Foundation. | |
11 | * | |
12 | * The above named program is distributed in the hope that it will be | |
13 | * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 | * General Public License for more details. | |
16 | * | |
17 | * You should have received a copy of the GNU General Public | |
18 | * License along with this work; if not, write to the Free Software | |
19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. | |
20 | * | |
21 | * ========== Copyright Header End ============================================ | |
22 | */ | |
23 | /* | |
24 | * Copyright 2006 Sun Microsystems, Inc. All rights reserved. | |
25 | * Use is subject to license terms. | |
26 | */ | |
27 | ||
28 | #pragma ident "@(#)fileutil.c 1.6 06/07/20 SMI" | |
29 | ||
30 | #include <stdio.h> | |
31 | #include <stdarg.h> | |
32 | #include <unistd.h> | |
33 | #include <errno.h> | |
34 | #include <sys/types.h> | |
35 | #include <sys/stat.h> | |
36 | ||
37 | #include "basics.h" | |
38 | #include "fatal.h" | |
39 | ||
40 | FILE * | |
41 | fopen_check(char * fnamep, char * optsp) | |
42 | { | |
43 | FILE * fp; | |
44 | ||
45 | fp = fopen(fnamep, optsp); | |
46 | if (fp == NULL) | |
47 | fatal("failed opening %s", fnamep); | |
48 | return fp; | |
49 | } | |
50 | ||
51 | ||
52 | bool_t | |
53 | file_exists(char * fnamep) | |
54 | { | |
55 | struct stat sb; | |
56 | int res; | |
57 | ||
58 | do { | |
59 | res = stat(fnamep, &sb); | |
60 | } while (res == -1 && errno == EAGAIN); | |
61 | ||
62 | return (res == 0); | |
63 | } | |
64 | ||
65 | ||
66 | bool_t | |
67 | is_a_dir(char * dirnamep) | |
68 | { | |
69 | struct stat sb; | |
70 | ||
71 | if (dirnamep == NULL) | |
72 | return false; | |
73 | ||
74 | if (stat(dirnamep, &sb) < 0) | |
75 | return false; | |
76 | ||
77 | return S_ISDIR(sb.st_mode); | |
78 | } |