/[PAMELA software]/yoda/event/DirectoryStructure.c
ViewVC logotype

Annotation of /yoda/event/DirectoryStructure.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4.0 - (hide annotations) (download)
Sun Mar 6 04:33:01 2005 UTC (19 years, 8 months ago) by kusanagi
Branch: MAIN
CVS Tags: yodaPreTermistors2_1/00, YODA4_1/00, YODA4_0/04, YODA4_0/03, YODA4_0/02, YODA4_0/01, YODA4_3/02, YODA4_3/00, YODA4_3/01, YODA4_2/01, YODA4_2/00, YODA4_2/03, yodaPreTermistores2_0/00
Branch point for: PreThermistores2
Changes since 3.0: +1 -1 lines
File MIME type: text/plain
Stable version 4.0 - 6 March 2005 - Maurizio Nagni

1 kusanagi 1.1 /** @file
2 kusanagi 2.0 * $Source: /home/cvsmanager/yoda/event/DirectoryStructure.c,v $
3 kusanagi 4.0 * $Id: DirectoryStructure.c,v 3.0 2005/03/04 15:54:11 kusanagi Exp $
4 kusanagi 2.0 * $Author: kusanagi $
5 kusanagi 1.1 *
6     * Implementation of the CreateDirectoryStructure function.
7     */
8    
9     #include <sys/stat.h>
10     #include <sys/types.h>
11     #include <string.h>
12     #include <stdlib.h>
13     #include <stdio.h>
14    
15     #include "DirectoryStructure.h"
16    
17     /**
18     * Create all directories that are needed to create a certain file name.
19     * @param FileName file name with the path.
20     * @retval 0 everything was OK.
21     * @retval -1 an error occurred, errno is set accordingly.
22     */
23     int CreateDirectoryStructure(const char *FileName) {
24     const char *pathend;
25     char *path = malloc(strlen(FileName) + 1);
26     struct stat buf;
27    
28     for (pathend = FileName+1; pathend != NULL;
29     pathend = strchr(pathend+1, '/')) {
30     strncpy(path, FileName, (pathend - FileName));
31     path[pathend - FileName] = '\0';
32     if (stat(path, &buf) != 0) {
33     if (mkdir(path, S_IRWXU | S_IRWXG | S_IRWXO) != 0) {
34     return -1;
35     }
36     }
37     }
38     return 0;
39     }
40    

  ViewVC Help
Powered by ViewVC 1.1.23