2 Copyright © 1995-2014, The AROS Development Team. All rights reserved.
8 #include <exec/memory.h>
9 #include <exec/execbase.h>
10 #include <proto/exec.h>
12 #include <proto/dos.h>
13 #include <utility/tagitem.h>
15 const TEXT version
[] = "$VER: MakeDir 42.6 (3.4.2014)\n";
17 /******************************************************************************
33 Create new empty directories with specified names.
37 NAME -- names of the directories that should be created
38 ALL -- creates intermediate directories
44 MakeDir does not create an icon for a new directory.
54 ******************************************************************************/
64 BPTR
CreateDirAll(STRPTR name
);
70 IPTR args
[NOOFARGS
] = { (IPTR
) NULL
};
73 LONG result
= RETURN_OK
;
77 rda
= ReadArgs("NAME/M/A,ALL/S", args
, NULL
);
82 STRPTR
*name
= (STRPTR
*)args
[ARG_NAME
];
84 if((name
== NULL
) || (*name
== NULL
))
86 error
= ERROR_REQUIRED_ARG_MISSING
;
91 for(i
= 0; name
[i
] != NULL
; i
++)
94 lock
= CreateDirAll(name
[i
]);
96 lock
= CreateDir(name
[i
]);
98 /* The AmigaDOS semantics are quite strange here. When it is
99 impossible to create a certain directory, MakeDir goes on
100 to try to create the rest of the specified directories and
101 returns the LAST return value for the operation. */
110 PutStr("Cannot create directory ");
113 result
= RETURN_ERROR
;
121 result
= RETURN_FAIL
;
123 if(result
!= RETURN_OK
)
124 PrintFault(error
, "MakeDir");
131 * Walk path from left to right, Lock()ing each element. If locking fails,
133 * This routine is smart enough to try optimize multiple '/'s.
136 BPTR
CreateDirAll(STRPTR name
)
144 UBYTE _fib
[sizeof(struct FileInfoBlock
) + 3];
145 struct FileInfoBlock
*fib
= (APTR
) ((((IPTR
) _fib
) + 3) & ~3);
148 CurrentDir(oldcurdir
= CurrentDir(0));
154 if (c
== ':' || c
== '/' || c
== '\0')
162 error
= ERROR_DEVICE_NOT_MOUNTED
;
168 //Printf("Lock \"%s\"\n", (LONG) name);
169 l
= Lock(name
, ACCESS_READ
);
176 while (pt
[skip
] == '/')
184 //Printf("Lock \"%s\"\n", (LONG) name);
185 l
= Lock(name
, ACCESS_READ
);
189 skip
= *name
!= '/' && c
== '/' ? -1 : 0;
193 //Printf("CreateDir \"%s\"\n", (LONG) name);
194 l
= name
[0] == '/' || name
[0] == '\0' ? 0 : CreateDir(name
);
197 if (!ChangeMode(CHANGE_LOCK
, l
, ACCESS_READ
))
200 l
= Lock(name
, ACCESS_READ
);
208 /* Make sure it's a directory */
209 if (!(res
= Examine(l
, fib
)) || fib
->fib_DirEntryType
< 0)
214 error
= (c
== '\0' ? ERROR_OBJECT_EXISTS
: ERROR_OBJECT_WRONG_TYPE
);
239 //Printf("return success\n");
240 return CurrentDir(oldcurdir
);
247 o
= CurrentDir(oldcurdir
);
253 //Printf("return error\n");