comparison ezBAMQC/src/htslib/cram/files.c @ 0:dfa3745e5fd8

Uploaded
author youngkim
date Thu, 24 Mar 2016 17:12:52 -0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:dfa3745e5fd8
1 /*
2 Copyright (c) 1994, 1996-1997, 2000, 2003 MEDICAL RESEARCH COUNCIL
3 All rights reserved
4
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are met:
7
8 1 Redistributions of source code must retain the above copyright notice,
9 this list of conditions and the following disclaimer.
10
11 2 Redistributions in binary form must reproduce the above copyright notice,
12 this list of conditions and the following disclaimer in the documentation
13 and/or other materials provided with the distribution.
14
15 3 Neither the name of the MEDICAL RESEARCH COUNCIL, THE LABORATORY OF
16 MOLECULAR BIOLOGY nor the names of its contributors may be used to endorse or
17 promote products derived from this software without specific prior written
18 permission.
19
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
21 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
24 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
27 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 #ifdef HAVE_CONFIG_H
33 #include "io_lib_config.h"
34 #endif
35
36 #include "cram/misc.h"
37
38 #include <sys/types.h>
39 #include <sys/stat.h>
40 /* Alliant's Concentrix <sys/stat.h> is hugely deficient */
41 /* Define things we require in this program */
42 /* Methinks S_IFMT and S_IFDIR aren't defined in POSIX */
43 #ifndef S_ISDIR
44 #define S_ISDIR(m) (((m)&S_IFMT) == S_IFDIR)
45 #endif /*!S_ISDIR*/
46 #ifndef S_ISREG
47 #define S_ISREG(m) (((m)&S_IFMT) == S_IFREG)
48 #endif /*!S_ISREG*/
49
50 int is_directory(char * fn)
51 {
52 struct stat buf;
53 if ( stat(fn,&buf) ) return 0;
54 return S_ISDIR(buf.st_mode);
55 }
56
57 int is_file(char * fn)
58 {
59 struct stat buf;
60 if ( stat(fn,&buf) ) return 0;
61 return S_ISREG(buf.st_mode);
62 }
63
64 int file_exists(char * fn)
65 {
66 struct stat buf;
67 return ( stat(fn,&buf) == 0);
68 }
69
70 int file_size(char * fn)
71 {
72 struct stat buf;
73 if ( stat(fn,&buf) != 0) return 0;
74 return buf.st_size;
75 }
76