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

Annotation of /chewbacca/event/DirectoryStructure.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1.1.1 - (hide annotations) (download) (vendor branch)
Tue Sep 23 07:19:50 2008 UTC (16 years, 2 months ago) by mocchiut
Branch: v0r00, MAIN
CVS Tags: v1r02, v1r00, v1r01, start, v10RED, v9r00, v9r01, HEAD
Changes since 1.1: +0 -0 lines
File MIME type: text/plain
Imported sources, 23/09/2008

1 mocchiut 1.1 /** @file
2     * $Source: /repository/event/DirectoryStructure.c,v $
3     * $Id: DirectoryStructure.c,v 1.1 2008-01-11 17:14:21 messineo Exp $
4     * $Author: messineo $
5     *
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