Login
Username:

Password:

Remember me



Lost Password?

Register now!

Sections

Who's Online
142 user(s) are online (130 user(s) are browsing Forums)

Members: 0
Guests: 142

more...

Support us!

Headlines

 
  Register To Post  

(1) 2 »
Change and create directory with chdir/mkdir
Quite a regular
Quite a regular


See User information
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
Go to top
Re: Change and create directory with chdir/mkdir
Just can't stay away
Just can't stay away


See User information
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>
Go to top
Re: Change and create directory with chdir/mkdir
Quite a regular
Quite a regular


See User information
@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
Go to top
Re: Change and create directory with chdir/mkdir
Home away from home
Home away from home


See User information
@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.
Go to top
Re: Change and create directory with chdir/mkdir
Just can't stay away
Just can't stay away


See User information
@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>
Go to top
Re: Change and create directory with chdir/mkdir
Quite a regular
Quite a regular


See User information
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
Go to top
Re: Change and create directory with chdir/mkdir
Just can't stay away
Just can't stay away


See User information
@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).

Go to top
Re: Change and create directory with chdir/mkdir
Quite a regular
Quite a regular


See User information
@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
Go to top
Re: Change and create directory with chdir/mkdir
Just can't stay away
Just can't stay away


See User information
@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.

Go to top
Re: Change and create directory with chdir/mkdir
Quite a regular
Quite a regular


See User information
@salass00

the errno is -1.

Directory flags are rwed

Retired
Go to top
Re: Change and create directory with chdir/mkdir
Just can't stay away
Just can't stay away


See User information
@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.

Go to top
Re: Change and create directory with chdir/mkdir
Quite a regular
Quite a regular


See User information
"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
Go to top
Re: Change and create directory with chdir/mkdir
Just can't stay away
Just can't stay away


See User information
@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")?


Go to top
Re: Change and create directory with chdir/mkdir
Quite a regular
Quite a regular


See User information
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
Go to top
Re: Change and create directory with chdir/mkdir
Just can't stay away
Just can't stay away


See User information
@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.

Go to top
Re: Change and create directory with chdir/mkdir
Quite a regular
Quite a regular


See User information
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
Go to top
Re: Change and create directory with chdir/mkdir
Just can't stay away
Just can't stay away


See User information
@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.

Go to top
Re: Change and create directory with chdir/mkdir
Quite a regular
Quite a regular


See User information
@salass00

"/PROGDIR/data/mydata" instead."

Already tried with PROGDIR without result.

Let me do some other tests.


Retired
Go to top
Re: Change and create directory with chdir/mkdir
Just can't stay away
Just can't stay away


See User information
@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 argvchar **argc)
{
    
char *dir "/ram/t";
    
char *newdir "newdir";

    if ((
chdir(dir) !=0))
    {
        
printf("chdir failed\n");
        return 
0;
    }

    if ((
mkdir(newdirS_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

Go to top
Re: Change and create directory with chdir/mkdir
Quite a regular
Quite a regular


See User information
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
Go to top

  Register To Post
(1) 2 »

 




Currently Active Users Viewing This Thread: 1 ( 0 members and 1 Anonymous Users )




Powered by XOOPS 2.0 © 2001-2024 The XOOPS Project