1 /***************************************************************************
2 * This file is a part of CADS/UVS fits2jpeg conversion software *
3 * Copyright (C) 2012 by CADS/UV Software Team, *
4 * Indian Institute of Astrophysics *
5 * Bangalore 560034 *
6 * cads_AT_iiap.res.in *
7 * *
8 * This program is free software; you can redistribute it and/or modify *
9 * it under the terms of the GNU General Public License as published by *
10 * the Free Software Foundation; either version 2 of the License, or *
11 * (at your option) any later version. *
12 * *
13 * This program is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16 * GNU General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU General Public License *
19 * along with this program; if not, write to the *
20 * Free Software Foundation, Inc., *
21 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
22 ***************************************************************************/
24 /*Header Definitions*/
25 #include "fits2jpeg.h"
27 /*---------------------------------------------------------------------------*/
28 int make_dir(char * folder, mode_t mode)
29 {
30 struct stat st;
31 int status = 0;
33 if (stat(folder, &st) != 0)
34 {
35 /* Directory does not exist - make it */
36 status = mkdir(folder, mode);
37 if (status) return status;
38 }
39 else if (!S_ISDIR(st.st_mode))
40 return status = -1;
41 return status;
42 }
44 int make_tree(char * folder, mode_t mode)
45 {
46 char *pp;
47 char *sp;
48 int status = 0;
49 char *fpath = strdup(folder);
51 pp = fpath;
53 while (status == 0 && (sp = strchr(pp, '/')) != 0)
54 {
55 if (sp != pp)
56 {
57 *sp = '\0';
58 status = make_dir(fpath, mode);
59 *sp = '/';
60 }
61 pp = sp + 1;
62 }
64 if (status == 0) status = make_dir(folder, mode);
65 return status;
66 }
68 char *strdup(const char *str)
69 {
70 int n = strlen(str) + 1;
71 char *dup = malloc(n);
72 if(dup)
73 {
74 strcpy(dup, str);
75 }
76 return dup;
77 }