/*************************************************************************** * This file is a part of CADS/UVS fits2jpeg conversion software * * Copyright (C) 2012 by CADS/UV Software Team, * * Indian Institute of Astrophysics * * Bangalore 560034 * * cads_AT_iiap.res.in * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ /*Header Definitions*/ #include "fits2jpeg.h" /*---------------------------------------------------------------------------* * MAKE_DIR: Wrapper to mkdir() with some basic error checks *---------------------------------------------------------------------------*/ int make_dir(char * folder, mode_t mode) { struct stat st; int status = 0; if (stat(folder, &st) != 0) { /* Directory does not exist - make it */ status = mkdir(folder, mode); if (status) return status; } else if (!S_ISDIR(st.st_mode)) return status = -1; return status; } /*---------------------------------------------------------------------------* * MAKE_TREE: moves through a directory path and creates directories and * subdirectories using make_dir(), top-down. *---------------------------------------------------------------------------*/ int make_tree(char * folder, mode_t mode) { char *pp; char *sp; int status = 0; char *fpath = strdup(folder); pp = fpath; while (status == 0 && (sp = strchr(pp, '/')) != 0) { if (sp != pp) { *sp = '\0'; status = make_dir(fpath, mode); *sp = '/'; } pp = sp + 1; } if (status == 0) status = make_dir(folder, mode); return status; } /*---------------------------------------------------------------------------* * STRDUP: This one is not a part of ANSI-strict, so we had to write one *---------------------------------------------------------------------------*/ char *strdup(const char *str) { int n = strlen(str) + 1; char *dup = malloc(n); if(dup) { strcpy(dup, str); } return dup; }