LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-04-2012, 01:55 AM   #1
Abishek
LQ Newbie
 
Registered: Aug 2012
Posts: 1

Rep: Reputation: Disabled
Truncation operation not performed


#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>
#include<unistd.h>
#include<string.h>
#include<stdio.h>
#include<stdlib.h>
int main(){
int d,i;
char buf[50];
bzero(buf,50);
for(i=0;i<3;i++){
read(0,buf,50);
d = open("h.c",O_RDWR|O_TRUNC);
if(d<0){
printf("error");
exit(0);
}
printf("%d\n",d);
write(d,buf,50);
write(1,buf,50);
close(d);
}
}



in this program why the truncated operation is not performing on file
 
Old 08-04-2012, 02:06 AM   #2
SIG_SEGV
Member
 
Registered: Jul 2012
Location: Banglore, INDIA
Distribution: Fedora-Core
Posts: 70

Rep: Reputation: 11
Is it appending ?????
 
Old 08-04-2012, 02:08 AM   #3
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
Some other things: please use more descriptive thread titles, as you're asked to when posting threads here. Also, when posting code, please put it within [code] and [/code] to preserve indentation and aid readability.

Last edited by Nylex; 08-04-2012 at 02:23 AM.
 
1 members found this post helpful.
Old 08-04-2012, 02:23 AM   #4
414N
Member
 
Registered: Sep 2011
Location: Italy
Distribution: Slackware
Posts: 647

Rep: Reputation: 189Reputation: 189
What truncation operation?
If you're referring to the use of the O_TRUNC flag inside open() maybe you misunderstood its function:
Quote:
Originally Posted by man 2 open
O_TRUNC
If the file already exists and is a regular file and the open mode allows
writing (i.e., is O_RDWR or O_WRONLY) it will be truncated to length 0. If
the file is a FIFO or terminal device file, the O_TRUNC flag is ignored.
Otherwise the effect of O_TRUNC is unspecified.
 
  


Reply



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 On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
MP3 Truncation mmiikkee12 Linux - Software 2 09-02-2007 01:19 AM
No X11 DISPLAY variable was set, but this program performed an operation which requir ernestkok Fedora 1 04-04-2007 07:10 PM
C++ Rounding and Truncation Opeth Programming 4 09-17-2005 07:16 PM
filename truncation Perl belmer2 Programming 1 04-24-2005 01:31 PM
Truncation problem Big Al Debian 3 04-12-2004 08:26 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:34 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration