Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

open modes wrong on linux #1

Open
pahhur opened this issue Jul 28, 2019 · 1 comment
Open

open modes wrong on linux #1

pahhur opened this issue Jul 28, 2019 · 1 comment

Comments

@pahhur
Copy link

pahhur commented Jul 28, 2019

Linux:

object files are created with mode = 0 at my site (my umask 0077)
In unix terms, the rights for the object files are just ----------)

as6502$ grep -n O_CREAT *.c
lib6502.c:72: int handle = open(libname, O_RDONLY | O_CREAT, 255);
lib6502.c:224: handle = open(obj->modname, O_WRONLY | O_CREAT | O_TRUNC, 255);
main.c:105: objfile = open(objname, O_WRONLY | O_CREAT);

Cite open man page on Linux:
" The mode argument specifies the file mode bits be applied when a
new file is created. This argument must be supplied when
O_CREAT or O_TMPFILE is specified in flags;"

For the first open: please check if you really mean to open the file like that.
For all items and linux: specify a value of 0640

Keep in mind, that other os' need other values here.

---- the correct version for linux might be -------
lib6502.c:72: int handle = open(libname, O_RDONLY | O_CREAT, 0640);
lib6502.c:224: handle = open(obj->modname, O_WRONLY | O_CREAT | O_TRUNC, 0640);
main.c:105: objfile = open(objname, O_WRONLY | O_CREAT, 0640);

@pahhur
Copy link
Author

pahhur commented Jul 30, 2019

I forgot:

You can use
_S_IREAD | _S_IWRITE
under Windows, and
S_IRUSR | S_IWUSR | S_IRGRP
under Linux.

So something like the following in a header file would do the job:

#if defined(_linux_) || defined(_GNUC_)
#include <fcntl.h>
#define OPEN_MODE (S_IRUSR | S_IWUSR | S_IRGRP)
#elif defined(__WIN32)
#define OPEN_MODE (_S_IREAD | _S_IWRITE)

/*
other os defines here
*/
#endif

There are two underscores before and after the linux, as well as before and after the GNUC

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant