2 Copyright © 1995-2004, 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>
17 static const char version
[] = "$VER: MakeDir 42.4 (17.10.2005)\n";
19 /******************************************************************************
35 Create new empty directories with specified names.
39 NAME -- names of the directories that should be created
40 ALL -- creates intermediate directories
46 MakeDir does not create an icon for a new directory.
56 ******************************************************************************/
66 BPTR
CreateDirAll(STRPTR name
);
72 IPTR args
[NOOFARGS
] = { (IPTR
) NULL
};
75 LONG error
= RETURN_OK
;
78 rda
= ReadArgs("NAME/M,ALL/S", args
, NULL
);
83 STRPTR
*name
= (STRPTR
*)args
[ARG_NAME
];
85 if((name
== NULL
) || (*name
== NULL
))
87 PutStr("No name given\n");
92 for(i
= 0; name
[i
] != NULL
; i
++)
95 lock
= CreateDirAll(name
[i
]);
97 lock
= CreateDir(name
[i
]);
99 /* The AmigaDOS semantics are quite strange here. When it is
100 impossible to create a certain directory, MakeDir goes on
101 to try to create the rest of the specified directories and
102 returns the LAST return value for the operation. */
110 PutStr("Cannot create directory ");
113 error
= RETURN_ERROR
;
123 if(error
!= RETURN_OK
)
124 PrintFault(IoErr(), NULL
);
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);
147 CurrentDir(oldcurdir
= CurrentDir(0));
153 if (c
== ':' || c
== '/' || c
== '\0')
161 SetIoErr(ERROR_DEVICE_NOT_MOUNTED
);
167 //Printf("Lock \"%s\"\n", (LONG) name);
168 l
= Lock(name
, ACCESS_READ
);
175 while (pt
[skip
] == '/')
183 //Printf("Lock \"%s\"\n", (LONG) name);
184 l
= Lock(name
, ACCESS_READ
);
188 skip
= *name
!= '/' && c
== '/' ? -1 : 0;
192 //Printf("CreateDir \"%s\"\n", (LONG) name);
193 l
= name
[0] == '/' || name
[0] == '\0' ? 0 : CreateDir(name
);
196 if (!ChangeMode(CHANGE_LOCK
, l
, ACCESS_READ
))
199 l
= Lock(name
, ACCESS_READ
);
207 /* Make sure it's a directory */
208 if (!(res
= Examine(l
, fib
)) || fib
->fib_DirEntryType
< 0)
213 SetIoErr(c
== '\0' ? ERROR_OBJECT_EXISTS
: ERROR_OBJECT_WRONG_TYPE
);
238 //Printf("return success\n");
239 return CurrentDir(oldcurdir
);
246 o
= CurrentDir(oldcurdir
);
252 //Printf("return error\n");