File: hpmkdir.c

package info (click to toggle)
hfsplus 1.0.4-21
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,948 kB
  • sloc: ansic: 7,726; makefile: 54
file content (166 lines) | stat: -rw-r--r-- 3,328 bytes parent folder | download | duplicates (9)
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/*
 * hfsputils - tools for reading and writing Macintosh HFS+ volumes
 *
 * create a new folder in the current (HFS+) working directory
 *
 * Copyright (C) 2000 Klaus Halfmann <klaus.halfmann@feri.de>
 * Original 1996-1998 Robert Leslie <rob@mars.org>
 * Additional work by  Brad Boyer (flar@pants.nu)
 *
 * 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
 *
 * $Id: hpmkdir.c,v 1.1.1.1 2002/03/05 19:50:29 klaus Exp $
 */
  
# ifdef HAVE_CONFIG_H
#  include "config.h"
# endif

# ifdef HAVE_UNISTD_H
#  include <unistd.h>
# endif
/*

# ifdef HAVE_TERMIOS_H
#  include <termios.h>
# endif

# ifdef HAVE_SYS_IOCTL_H
#  include <sys/ioctl.h>
# else
int ioctl(int, int, ...);
# endif

# include <string.h>
# include <time.h>
# include <ctype.h>
# include <errno.h>
*/
# include <stdio.h>
# include <stdlib.h>

# include "libhfsp.h"
# include "record.h"
// # include "hfstime.h"
# include "volume.h"
# include "unicode.h"

#include "darray.h"
#include "dlist.h"
#include "dstring.h"
#include "hpcache.h"
#include "hfsputil.h"

/*
 * NAME:	usage()
 * DESCRIPTION:	display usage message
 */
static
int usage()
{
  fprintf(stderr, "Usage: %s hfs-path ...\n", argv0);

  return 1;
}

/* create all the folders specified in the argvs.
 *
 * rec, base directory where files are found.
 *
 */
static
int do_mkdir(record *rec, int argc, char *argv[], int flags)
{
    int i;
    int result = 0;

    for (i = 0; i < argc; ++i)
    {
	record	folder; 
	char*	argi = argv[i];
	if (record_init_string(&folder, HFSP_FOLDER, argi, rec))
	{
	    hfsputil_perrorp(argi);
	    HFSP_ERROR(-1, 0);
	}
	else if (record_insert(&folder))
	{
	    hfsputil_perrorp(argi);
	    HFSP_ERROR(errno, 0);

	    result = 1;
	}
    }

    return result;
  fail:
    return -1;
}

/*
 * NAME:	hpmkdir->main()
 * DESCRIPTION:	implement hpmkdir command
 */
int main(int argc, char *argv[])
{
    volume	vol;
    record	rec;

    int		nargs, result = 0;
    int		fargc, flags  = 0;
    char	**fargv;

    argv0 = argv[0];
    while (1) // Our only option is -?/-h
    {
	int opt;

	opt = getopt(argc, argv, "h");
	if (opt == EOF)
	    break;

	switch (opt)
	{
	  case '?':
	  case 'h':
	    return usage();
	}
    }

    nargs = argc - optind;

    if (nargs < 1)
	return usage();

    if (hpcache_reopen(&vol,&rec,HFSP_MODE_RDWR))
        goto fail;

    fargv = hfsputil_glob(&rec, nargs, &argv[optind], &fargc, &result);

    if (!result)
	result = do_mkdir(&rec, fargc, fargv, flags);

    result = volume_close(&vol) || result;

    if (fargv && fargv != &argv[optind])
	free(fargv);

    if (result)
	hfsputil_perrorp(argv0);
    return result;
  fail:
    hfsputil_perrorp(argv0);
    return -1;
}