Top DevX Stories
Creating Custom Export Filters for StarOffice with XSLT
WPF Wonders: Using DataTemplates
Crystal Reports Family Offers Options for Developers
Avaya Aura Session Manager video
Avaya Aura Overview video
Search the forums:
  #1  
Old 10-22-2009, 07:27 AM
ami ami is offline
Registered User
 
Join Date: May 2004
Posts: 187
chmod

Hello everyone,

Can someone please tell me whether there is the equivalent of chmod in Standard C++, i.e. change permissions on a file ?

I don't really want to use the system command ?

I found that I can do :-

char fn[]="./temp.file";
FILE *stream;

if ((stream = fopen(fn, "w")) != NULL)
{
if (chmod(fn, S_IRGRP|S_IRWXU|S_IROTH ) != 0)
{
perror("chmod() error");
}
fclose(stream);
}

But the issue here is that I need to use the old fashioned way of reading a file line by line, rather than use fstream.

Can I cast from std::fstream to const char* ?

Many thanks.

Last edited by ami; 10-22-2009 at 08:03 AM.
Reply With Quote
  #2  
Old 10-22-2009, 09:40 AM
jonnin jonnin is offline
Senior Member
 
Join Date: Dec 2003
Posts: 3,008
I do not really understand your question:

- chmod as you have it does not care what file type you used, it is operating off the file name!

-you did not use fstream, you used a FILE*

If you want to read a text file line by line, use ifstream and getline. Or read the entire file into a buffer if its small and split it up using string functions, based off the end of line markers.

You cannot convert from a file object to a char * safely and expect the char * to contain the file's data. You can read the whole file into an allocated char * or array. Or part of the file, all the way down to 1 char into a char variable.

Try again, what exactly are you wanting to do?

Here is how to read line by line:
ifstream ifs;
ifs.open(fn);
ifs.getline(buffer, max_length);
//buffer is a char* or unsigned char* you can use it directly, or poke it into a string, or you can read directly into a string variable (I am fairly sure).
Reply With Quote
  #3  
Old 10-22-2009, 12:43 PM
Danny's Avatar
Danny Danny is offline
Super Moderator
 
Join Date: Nov 2003
Posts: 3,948
There's no equivalent of chmod in standard C++. However, chmod is rather portable function. If and when the FleSystem library is added to standard C++ is hard to tell at this stage (it won't happpen in C++0x).
__________________
Danny Kalev
Reply With Quote
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP upload question leafdodger Web 2 12-12-2006 09:41 AM


All times are GMT -4. The time now is 10:01 PM.


Sponsored Links



Acceptable Use Policy

internet.comMediabistrojusttechjobs.comGraphics.com

WebMediaBrands Corporate Info


Advertise | Newsletters | Feedback | Submit News

Legal Notices | Licensing | Permissions | Privacy Policy


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.