Sponsored Content
Top Forums UNIX for Dummies Questions & Answers int open(const char *pathname, int flags, mode_t mode) doubt... Post 302145817 by csnmgeek on Thursday 15th of November 2007 09:31:19 AM
Old 11-15-2007
int open(const char *pathname, int flags, mode_t mode) doubt...

hello everybody!

I want to create a file with permissions for read, write, and execute to everybody using C, so I write this code:

Code:
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

int main(){
   int fileDescriptor;
   fileDescriptor = open("./NewFile", O_CREAT, S_IRWXU|S_IRWXG|S_IRWXO );
   printf("File Descriptor: %d\n", fileDescriptor);
   close(fileDescriptor);

   return 0;
}

I expected to have the following result:

$ ls -l NewFile
-rwxrwxrwx 1 csnmgeek csnmgeek 0 2007-11-15 09:23 NewFile

but instead I got this:

$ ls -l NewFile
-rwxr-xr-x 1 csnmgeek csnmgeek 0 2007-11-15 09:23 NewFile

Can you tell me where is the problem?
regards
jorge
 

10 More Discussions You Might Find Interesting

1. Programming

difference between int ** func() and int *& func()

What is the difference between int** func() and int*& func(). Can you please explain it with suitable example. Thanks, Devesh. (1 Reply)
Discussion started by: devesh
1 Replies

2. Red Hat

cast from const void* to unsigned int loses precision

Hello everey one, here i am attempting to compile a c++ project .it's throughing the following errors. my machine details are as follows: Linux chmclozr0119 2.6.18-53.el5 #1 SMP Wed Oct 10 16:34:19 EDT 2007 x86_64 x86_64 x86_64 GNU/Linux errors: ===== Generating... (0 Replies)
Discussion started by: mannam srinivas
0 Replies

3. Programming

How to read flags from mode_t type?

Hello, After, I stat() a file, how can I read the various permissions flags from the st_mode variable which is of type mode_t? I would like to do something like: struct stat *perms; int res = stat(filename, perms); if(perms->st.mode == S_IROTH) do something; but I know that is the wrong... (2 Replies)
Discussion started by: pallak7
2 Replies

4. Programming

concat const char * with char *

hello everybody! i have aproblem! i dont know how to concatenate const char* with char const char *buffer; char *b; sprintf(b,"result.txt"); strcat(buffer,b); thanx in advance (4 Replies)
Discussion started by: nicos
4 Replies

5. Programming

conversion to 'char' from 'int' warning

Hi, I wrote a simple code in C++ converting from UpperToLower case characters. However, my compiler gives me a warning: "warning: conversion to 'char' from 'int' may alter its value". Any tips? I would like to stress, I don't want to load my string into char array. int ToLower(string... (4 Replies)
Discussion started by: kajolo
4 Replies

6. Programming

Handle int listen(int sockfd, int backlog) in TCP

Hi, from the manual listen(2): listen for connections on socket - Linux man page It has a parameter called backlog and it limits the maximum length of queue of pending list. If I set backlog to 128, is it means no more than 128 packets can be handled by server? If I have three... (3 Replies)
Discussion started by: sehang
3 Replies

7. Programming

C++ program is crashing on re-assigning const static member variable using an int pointer

Hi, Can any one tell me why my following program is crashing? #include <iostream> using namespace std; class CA { public: const static int i; }; const int CA::i = 10; int main() { int* pi = const_cast<int*>(&CA::i); *pi = 9; cout << CA::i << endl; } (6 Replies)
Discussion started by: royalibrahim
6 Replies

8. Programming

error: invalid conversion from ‘const char*’ to ‘char*’

Compiling xpp (The X Printing Panel) on SL6 (RHEL6 essentially): xpp.cxx: In constructor ‘printFiles::printFiles(int, char**, int&)’: xpp.cxx:200: error: invalid conversion from ‘const char*’ to ‘char*’ The same error with all c++ constructors - gcc 4.4.4. If anyone can throw any light on... (8 Replies)
Discussion started by: GSO
8 Replies

9. Programming

Help with understanding ( int, char, long, short, signed, unsigned etc.... )

My question is simple: When should I use a long, int, char, unsigned/signed variables?? When I declare a variable "unsigned;" what did I do it??? Why would I delcare an integer "long" or "short" ( unsigned or signed)?? Any examples of when things like "unsigned", "long", "short" etc...... (6 Replies)
Discussion started by: cpp_beginner
6 Replies

10. Programming

Small query regarding function "char * strerror(int errnum)"

As this function returns the address of the string corressponding to the errno value provided to it. Can someone please let me know where, in the memory, it could be (on freeBSD). The MAN page tells under the BUG section that "For unknown error numbers, the strerror() function will return its... (5 Replies)
Discussion started by: Praveen_218
5 Replies
DIO_OPEN(3)								 1							       DIO_OPEN(3)

dio_open - Opens a file (creating it if necessary) at a lower level than the C library input/ouput stream functions allow.

SYNOPSIS
resource dio_open (string $filename, int $flags, [int $mode]) DESCRIPTION
dio_open(3) opens a file and returns a new file descriptor for it. PARAMETERS
o $filename - The pathname of the file to open. o $flags - The $flags parameter is a bitwise-ORed value comprising flags from the following list. This value must include one of O_RDONLY, O_WRONLY, or O_RDWR. Additionally, it may include any combination of the other flags from this list. o O_RDONLY - opens the file for read access. o O_WRONLY - opens the file for write access. o O_RDWR - opens the file for both reading and writing. o O_CREAT - creates the file, if it doesn't already exist. o O_EXCL - if both O_CREAT and O_EXCL are set and the file already exists, dio_open(3) will fail. o O_TRUNC - if the file exists and is opened for write access, the file will be truncated to zero length. o O_APPEND - write operations write data at the end of the file. o O_NONBLOCK - sets non blocking mode. o O_NOCTTY - prevent the OS from assigning the opened file as the process's controlling terminal when opening a TTY device file. o $mode - If $flags contains O_CREAT, $mode will set the permissions of the file (creation permissions). $mode is required for correct operation when O_CREAT is specified in $flags and is ignored otherwise. The actual permissions assigned to the created file will be affected by the process's umask setting as per usual. RETURN VALUES
A file descriptor or FALSE on error. EXAMPLES
Example #1 Opening a file descriptor <?php $fd = dio_open('/dev/ttyS0', O_RDWR | O_NOCTTY | O_NONBLOCK); dio_close($fd); ?> SEE ALSO
dio_close(3). PHP Documentation Group DIO_OPEN(3)
All times are GMT -4. The time now is 02:15 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy