2 Copyright © 1995-2007, 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 const TEXT version
[] = "$VER: MakeDir 42.5 (15.12.2007)\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 SetIoErr(ERROR_REQUIRED_ARG_MISSING
);
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 LONG lasterr
= IoErr(); // We don't want error from PutStr()
111 PutStr("Cannot create directory ");
115 error
= RETURN_ERROR
;
125 if(error
!= RETURN_OK
)
126 PrintFault(IoErr(), "MakeDir");
133 * Walk path from left to right, Lock()ing each element. If locking fails,
135 * This routine is smart enough to try optimize multiple '/'s.
138 BPTR
CreateDirAll(STRPTR name
)
146 UBYTE _fib
[sizeof(struct FileInfoBlock
) + 3];
147 struct FileInfoBlock
*fib
= (APTR
) ((((IPTR
) _fib
) + 3) & ~3);
149 CurrentDir(oldcurdir
= CurrentDir(0));
155 if (c
== ':' || c
== '/' || c
== '\0')
163 SetIoErr(ERROR_DEVICE_NOT_MOUNTED
);
169 //Printf("Lock \"%s\"\n", (LONG) name);
170 l
= Lock(name
, ACCESS_READ
);
177 while (pt
[skip
] == '/')
185 //Printf("Lock \"%s\"\n", (LONG) name);
186 l
= Lock(name
, ACCESS_READ
);
190 skip
= *name
!= '/' && c
== '/' ? -1 : 0;
194 //Printf("CreateDir \"%s\"\n", (LONG) name);
195 l
= name
[0] == '/' || name
[0] == '\0' ? 0 : CreateDir(name
);
198 if (!ChangeMode(CHANGE_LOCK
, l
, ACCESS_READ
))
201 l
= Lock(name
, ACCESS_READ
);
209 /* Make sure it's a directory */
210 if (!(res
= Examine(l
, fib
)) || fib
->fib_DirEntryType
< 0)
215 SetIoErr(c
== '\0' ? ERROR_OBJECT_EXISTS
: ERROR_OBJECT_WRONG_TYPE
);
240 //Printf("return success\n");
241 return CurrentDir(oldcurdir
);
248 o
= CurrentDir(oldcurdir
);
254 //Printf("return error\n");