File: misc.c

package info (click to toggle)
usbmgr 0.4.8-5
  • links: PTS
  • area: main
  • in suites: woody
  • size: 344 kB
  • ctags: 318
  • sloc: ansic: 2,067; sh: 539; makefile: 198
file content (45 lines) | stat: -rw-r--r-- 693 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/*
 *  
 *  Copyright (c) by Shuu Yamaguchi <shuu@wondernetworkresources.com>
 *
 *  $Id: misc.c,v 3.1 2000/12/01 11:07:26 shuu Exp $
 *
 *  Can be freely distributed and used under the terms of the GNU GPL.
 */

#include	<stdio.h>
#include	<unistd.h>
#include	<errno.h>
#include	<sys/stat.h>
#include	<string.h>

#include	"usbmgr.h"


static int
Mkdir(char *name)
{
	struct stat st;

	if (stat(name,&st) == -1) {
		if (errno == ENOENT) {
			return mkdir(name,0755);
		} else 
			return -1;
	} else if (!S_ISDIR(st.st_mode)) {
		return -1;
	}
	return 0;
}

void
Mkdir_R(char *path)
{
	char *ptr;

	for(ptr = path;ptr = strchr(ptr,'/');ptr++) {
		*ptr = '\0';
		Mkdir(path);
		*ptr = '/';
	}
}