Who's Online
51 user(s) are online (
36 user(s) are browsing
Forums )
Members: 1
Guests: 50
FlynnTheAvatar ,
more...
Topic options
View mode
Newest First
Change and create directory with chdir/mkdir
Posted on:
2016/10/22 17:46
#1
Quite a regular
Joined: 2006/11/22 17:57Last Login
: 6/4 16:05
From Italy, Rome
Group:
Registered Users
Hello everyone. Any example to use chdir to change directory and to use mkdir to create directory using POSIX style commands? if ((mkdir(dir, S_IRWXU) !=0) or similar commands seems are not working for me. Someone have a simple code example for this? Thank you very much
Retired
Re: Change and create directory with chdir/mkdir
Posted on:
2016/10/22 18:14
#2
Just can't stay away
Joined: 2006/11/24 18:52Last Login
: 2021/9/26 20:59
From Gloucestershire, UK.
Group:
Registered Users
Why POSIX style? OS4 uses CD & MakeDir, CD is optional, you can just type a path in shell to cd to it. The Amiga equivalent would be: cd somewhere makedir S_IRWXU if exists "S_IRWXU" ;do something else ;error endif
Amiga user since 1985 AOS4, A-EON, IBrowse & Alinea Betatester Ps. I hate the new amigans website. <shudder>
Re: Change and create directory with chdir/mkdir
Posted on:
2016/10/22 18:24
#3
Quite a regular
Joined: 2006/11/22 17:57Last Login
: 6/4 16:05
From Italy, Rome
Group:
Registered Users
@Severin "Why POSIX style?" Are used in a game that should be ported to OS4.1 I guess that "S_IRWXU" are directory permission access. What are the Amiga equivalent api for this?
Retired
Re: Change and create directory with chdir/mkdir
Posted on:
2016/10/22 23:51
#4
Home away from home
Joined: 2006/11/20 16:26Last Login
: Today 1:47
From Norway
Group:
Registered Users
@AmigaBlitter
Look here:
http://wiki.amigaos.net/wiki/AmigaOS_ ... Command_Reference#PROTECT Only if you have the SDK install, can you use some "Linux/Unix" type commands, you can type "SH" to can get into some kind of Unix shell.
(NutsAboutAmiga) Basilisk II for AmigaOS4 AmigaInputAnywhere Excalibur and other tools and apps.
Re: Change and create directory with chdir/mkdir
Posted on:
2016/10/23 0:56
#5
Just can't stay away
Joined: 2006/11/24 18:52Last Login
: 2021/9/26 20:59
From Gloucestershire, UK.
Group:
Registered Users
@AmigaBlitter hmmm... something like this in dos: cd path makedir dir if warn ;deal with something wrong. endif 'all is ok You can ignore protection bits, the default RWED is ok for most purposes.
Amiga user since 1985 AOS4, A-EON, IBrowse & Alinea Betatester Ps. I hate the new amigans website. <shudder>
Re: Change and create directory with chdir/mkdir
Posted on:
2016/10/23 10:57
#6
Quite a regular
Joined: 2006/11/22 17:57Last Login
: 6/4 16:05
From Italy, Rome
Group:
Registered Users
Thank you for the reply. I have, of course the SDK installed. Let me put the problem in this way. In porting a game, i fount this kind of commands in the source "if ((mkdir(dir, S_IRWXU) !=0)", as well as "if ((chdir(dir) !=0)". I noticed that this commands in posix style doesn't seems to work. As example, "if ((chdir(dir) !=0)" return error and i cannot change to the proper dir, although the directory exist. Now have someone else had similar problem? What are the amigaos api to use instead for this? Where can i found a simple example? Hope that this clarify my request
Retired
Re: Change and create directory with chdir/mkdir
Posted on:
2016/10/23 11:21
#7
Just can't stay away
Joined: 2006/11/30 11:30Last Login
: 11/18 16:17
From Finland
Group:
Registered Users
@AmigaBlitter If dir is an UNIX path, which it very likely is if you're porting a game from POSIX to AmigaOS, you should make sure you link the executable with -lunix. IDOS->SetCurrentDir() can't be used as a direct replacement for chdir() as with SetCurrentDir() you need to remember to set the current dir lock back to its original value on exit. Edit: Also you need to UnLock() any current dir locks you made yourself when they are not needed any more. All this is handled for you in the chdir() implementation. Just to be safe in case there is a permissions issue you could also try changing the second parameter of mkdir() from S_IRWXU to (S_IRWXU | S_IRWXG | S_IRWXO).
Re: Change and create directory with chdir/mkdir
Posted on:
2016/10/23 11:51
#8
Quite a regular
Joined: 2006/11/22 17:57Last Login
: 6/4 16:05
From Italy, Rome
Group:
Registered Users
@salass00 the executable is already linked with -lunix abd the mkdir command already come in this form (S_IRWXU | S_IRWXG | S_IRWXO). "IDOS->SetCurrentDir() can't be used as a direct replacement for chdir() as with SetCurrentDir() you need to remember to set the current dir lock back to its original value on exit." What i have exactly do? Is there an example somewhere?.
Retired
Re: Change and create directory with chdir/mkdir
Posted on:
2016/10/23 12:28
#9
Just can't stay away
Joined: 2006/11/30 11:30Last Login
: 11/18 16:17
From Finland
Group:
Registered Users
@AmigaBlitter What is the value of errno after chdir() has failed? Also have you checked what the protection flags of the created directory are? They should be "rwed" if the mkdir() call worked correctly.
Re: Change and create directory with chdir/mkdir
Posted on:
2016/10/23 14:08
#10
Quite a regular
Joined: 2006/11/22 17:57Last Login
: 6/4 16:05
From Italy, Rome
Group:
Registered Users
@salass00 the errno is -1. Directory flags are rwed
Retired
Re: Change and create directory with chdir/mkdir
Posted on:
2016/10/23 14:49
#11
Just can't stay away
Joined: 2006/11/30 11:30Last Login
: 11/18 16:17
From Finland
Group:
Registered Users
@AmigaBlitter The errno global variable should have a positive value. Are you sure you are checking the right value? The chdir() and mkdir() calls will return -1 for failure and 0 for success, however this is not the value I meant.
Re: Change and create directory with chdir/mkdir
Posted on:
2016/10/23 15:16
#12
Quite a regular
Joined: 2006/11/22 17:57Last Login
: 6/4 16:05
From Italy, Rome
Group:
Registered Users
"The errno global variable should have a positive value. Are you sure you are checking the right value?" res = chdir(dir.... res value is -1 Could pleas link a SetCurrentDir and Makedir Amiga api example?
Retired
Re: Change and create directory with chdir/mkdir
Posted on:
2016/10/23 15:33
#13
Just can't stay away
Joined: 2006/11/30 11:30Last Login
: 11/18 16:17
From Finland
Group:
Registered Users
@AmigaBlitter That's the return value of the function which says nothing about why it failed. To print out errno just add: fprintf(stderr, "errno: %d\n", errno); Also what version of newlib are you using (output of "version full newlib.library")?
Re: Change and create directory with chdir/mkdir
Posted on:
2016/10/23 19:56
#14
Quite a regular
Joined: 2006/11/22 17:57Last Login
: 6/4 16:05
From Italy, Rome
Group:
Registered Users
Sorry, the error is 2 "No such file or directory" It's a fresh install of OS 4.1 + latest SDK. Using gcc 6.1, btw. The error, however, appeared before 6.1 installation.
Retired
Re: Change and create directory with chdir/mkdir
Posted on:
2016/10/23 20:10
#15
Just can't stay away
Joined: 2006/11/30 11:30Last Login
: 11/18 16:17
From Finland
Group:
Registered Users
@AmigaBlitter
Quote:
Sorry, the error is 2 "No such file or directory"So ENOENT then. Could you check with Snoopy what path the code is trying to Lock()? Also what is the path that is passed to chdir()?
Quote:
It's a fresh install of OS 4.1 + latest SDK.That's not very specific. If you are using 4.1 Final Edition then you should have newlib.library version 53.30.
If you are using some older AmigaOS 4.1 version then I would rather not have to guess what version of newlib.library you have.
Re: Change and create directory with chdir/mkdir
Posted on:
2016/10/23 20:53
#16
Quite a regular
Joined: 2006/11/22 17:57Last Login
: 6/4 16:05
From Italy, Rome
Group:
Registered Users
OS 4.1 is FE. example of the dir that i try to change to in the code: /data/mydata/ Snoopy FAIL lock: Lock("data:mydata", SHARED)
Retired
Re: Change and create directory with chdir/mkdir
Posted on:
2016/10/23 21:23
#17
Just can't stay away
Joined: 2006/11/30 11:30Last Login
: 11/18 16:17
From Finland
Group:
Registered Users
@AmigaBlitter Unless you have a data: assign it is obvious why that fails. Rather than accessing data from root ("/data/mydata") you should probably have something like "/PROGDIR/data/mydata" instead. If you need help with fixing this correctly you will need to post a link to the complete source code of the game or at least post some more of the code so we can see how the path is being generated.
Re: Change and create directory with chdir/mkdir
Posted on:
2016/10/23 21:30
#18
Quite a regular
Joined: 2006/11/22 17:57Last Login
: 6/4 16:05
From Italy, Rome
Group:
Registered Users
@salass00 "/PROGDIR/data/mydata" instead." Already tried with PROGDIR without result. Let me do some other tests.
Retired
Re: Change and create directory with chdir/mkdir
Posted on:
2016/10/24 14:49
#19
Just can't stay away
Joined: 2008/1/6 17:56Last Login
: 2023/4/18 20:37
From Pennsylvania, USA
Group:
Registered Users
@AmigaBlitter
I wrote a quick test program to confirm that mkdir() and chdir() work and they do. Here is my quick test:
/* gcc testmk.c -o testmk -lunix -lauto -Wall */
#include <unistd.h>
#include <sys/stat.h>
#include <stdio.h>
int main ( int argv , char ** argc )
{
char * dir = "/ram/t" ;
char * newdir = "newdir" ;
if (( chdir ( dir ) != 0 ))
{
printf ( "chdir failed\n" );
return 0 ;
}
if (( mkdir ( newdir , S_IRWXU ) != 0 ))
{
printf ( "mkdir failed\n" );
}
else
{
printf ( "mkdir succeeded\n" );
rmdir ( "newdir" );
}
return 0 ;
}
Amiga X1000 with 2GB memory & OS 4.1FE + Radeon HD 5450
Re: Change and create directory with chdir/mkdir
Posted on:
2016/10/27 8:52
#20
Quite a regular
Joined: 2006/11/22 17:57Last Login
: 6/4 16:05
From Italy, Rome
Group:
Registered Users
Fixed. Seems that pointing to a nested direcotory as follow "/game/mygame" is interpreted as "/game:mygame". If i simply use "game/mygame" the path is interpreted correctly.
Retired
Currently Active Users Viewing This Thread:
1
(
0 members
and 1 Anonymous Users
)