2 Copyright © 1995-2014, The AROS Development Team. All rights reserved.
8 #include <proto/exec.h>
10 #include <proto/dos.h>
11 #include <utility/tagitem.h>
13 const TEXT version
[] = "$VER: MakeDir 42.7 (7.8.2016)\n";
15 /******************************************************************************
31 Create new empty directories with specified names.
35 NAME -- names of the directories that should be created
36 ALL -- creates intermediate directories
42 MakeDir does not create an icon for a new directory.
52 ******************************************************************************/
62 BPTR
CreateDirAll(STRPTR name
);
68 IPTR args
[NOOFARGS
] = { (IPTR
) NULL
};
71 LONG result
= RETURN_OK
;
75 rda
= ReadArgs("NAME/M/A,ALL/S", args
, NULL
);
80 STRPTR
*name
= (STRPTR
*)args
[ARG_NAME
];
82 if((name
== NULL
) || (*name
== NULL
))
84 error
= ERROR_REQUIRED_ARG_MISSING
;
89 for(i
= 0; name
[i
] != NULL
; i
++)
92 lock
= CreateDirAll(name
[i
]);
94 lock
= CreateDir(name
[i
]);
99 if (result
!= RETURN_ERROR
)
105 PutStr("Cannot create directory ");
108 result
= RETURN_ERROR
;
117 error
= ERROR_REQUIRED_ARG_MISSING
;
118 result
= RETURN_FAIL
;
121 if(result
!= RETURN_OK
)
122 PrintFault(error
, "MakeDir");
129 * Walk path from left to right, Lock()ing each element. If locking fails,
131 * This routine is smart enough to try optimize multiple '/'s.
134 BPTR
CreateDirAll(STRPTR name
)
142 UBYTE _fib
[sizeof(struct FileInfoBlock
) + 3];
143 struct FileInfoBlock
*fib
= (APTR
) ((((IPTR
) _fib
) + 3) & ~3);
146 CurrentDir(oldcurdir
= CurrentDir(0));
152 if (c
== ':' || c
== '/' || c
== '\0')
160 error
= ERROR_DEVICE_NOT_MOUNTED
;
166 //Printf("Lock \"%s\"\n", (LONG) name);
167 l
= Lock(name
, ACCESS_READ
);
174 while (pt
[skip
] == '/')
182 //Printf("Lock \"%s\"\n", (LONG) name);
183 l
= Lock(name
, ACCESS_READ
);
187 skip
= *name
!= '/' && c
== '/' ? -1 : 0;
191 //Printf("CreateDir \"%s\"\n", (LONG) name);
192 l
= name
[0] == '/' || name
[0] == '\0' ? 0 : CreateDir(name
);
195 if (!ChangeMode(CHANGE_LOCK
, l
, ACCESS_READ
))
198 l
= Lock(name
, ACCESS_READ
);
206 /* Make sure it's a directory */
207 if (!(res
= Examine(l
, fib
)) || fib
->fib_DirEntryType
< 0)
212 error
= (c
== '\0' ? ERROR_OBJECT_EXISTS
: ERROR_OBJECT_WRONG_TYPE
);
237 //Printf("return success\n");
238 return CurrentDir(oldcurdir
);
245 o
= CurrentDir(oldcurdir
);
251 //Printf("return error\n");