Sponsored Content
Top Forums Programming Writing files using O_DIRECT in C Post 302399566 by anchit87 on Sunday 28th of February 2010 11:20:25 PM
Old 03-01-2010
Here is the function. It does not write the entire image.
Code:
// imgdata is the image data to be written into a pgm image file

int writePgm( char* Filename, unsigned char* imgdata, int width, int height )
{
   void *buf;
   int ret=0;

   unsigned long long int bytes_written=0;
   int ps=getpagesize();
   posix_memalign(&buf, ps, height*width*2);  //each pixel is equvivalent to 2 bytes
   memcpy(buf ,imgdata, height*width*2);

   FILE* stream;
   int fd = open(Filename, O_CREAT | O_WRONLY |O_DIRECT, 00666);
   stream = fdopen(fd, "wb");

   if( stream == NULL)
   {
     perror( "Can't open image file" );
     return 1;
   }
   
   fprintf( stream, "P5\n%u %u 255\n", width, height );
   
   fwrite( buf, ps, width*height/ps, stream );
   
   fclose( stream );
   close(fd);
   return 0;
}

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

What files are writing to a directory

Is there a way to tell what files/scripts are writing/wrote to a given directory? (3 Replies)
Discussion started by: hattorihanzo
3 Replies

2. UNIX for Dummies Questions & Answers

Reading and Writing Files ?

Hello, Our group is just starting to get into UNIX here. We are former REXX users on a VM Mainframe. Can someone point me to the documentation to read a file and write a file in a Unix Shell Script or does this have to be done in another language? Thank you in advance... Dave (3 Replies)
Discussion started by: tracydp
3 Replies

3. UNIX for Dummies Questions & Answers

new to writing script files

thanks guys i managed to answer (0 Replies)
Discussion started by: bebop1111116
0 Replies

4. UNIX for Dummies Questions & Answers

Writing large files to tape

I have a zipped file that is ~ 10GB. I tried tarring it off to a tape, but I receive: tar: <filename> too large to archive. Use E function modifier. The file is stored on a UFS mount, so I was unable to use ufsdump. What other options do I have? (I don't have a local file system large... (3 Replies)
Discussion started by: FredSmith
3 Replies

5. Shell Programming and Scripting

Writing files without temporary files

Hey Guys, I was wondering if someone would give me a hand with an issue I'm having, let me explain the situation: I have a file that is constantly being written to and read from with updated lines: # cat activity.file activity1 activity2 activity3 activity4 activity5 This file... (2 Replies)
Discussion started by: bashshadow1979
2 Replies

6. UNIX for Dummies Questions & Answers

Writing a text to many files

Is there a command in shell-script that I can use that copies a string or writes it to many files? Say I have files a, b and c and I want to copy or write the text "Hallo, I am a newbie!" to all these files? I know I can do echo "Hallo, I am a newbie!" > a but this only copies it to one file. How... (2 Replies)
Discussion started by: #moveon
2 Replies

7. Shell Programming and Scripting

Testing for O_DIRECT support

Is there some was to test if opening with the O_DIRECT flag will work (without writing a C program)? (2 Replies)
Discussion started by: brsett
2 Replies

8. Shell Programming and Scripting

Problem writing to different files

Hello: I have the following code: ---------------------------------- open (OUTPUT_FILE, ">>/usr/users/rovolis/PREPAID/CC/TCG/PP.$cyear$cmonth$cday.txt")||die "$!"; 82 open (OUTPUT_FILE2, ">>/usr/users/rovolis/PREPAID/CC/TCG/PR.$cyear$cmonth$cday.txt")||die "$!"; 83 # ... (0 Replies)
Discussion started by: chriss_58
0 Replies

9. Shell Programming and Scripting

Writing to Memory Instead of Flat Files

i've always been of the mind that having to write to disk is very sloppy and dirty. i personally hate this. so i wonder, is there a way to have a shell script/program write to memory and access whatever it has in memory whenever it wants. pretty much treat memory like hard disk. can... (2 Replies)
Discussion started by: SkySmart
2 Replies

10. Filesystems, Disks and Memory

What is the difference between o_direct and DAX with ext4 filesystem?

I'm trying to understand the difference between o_direct flag of open system call and dax (direct access) with ext4 filesystem. According to my understanding both bypass page cache. But I'm still unclear about the crucial difference between these 2 techniques. If there is a huge difference... (1 Reply)
Discussion started by: BHASKAR JUPUDI
1 Replies
EXIF_THUMBNAIL(3)							 1							 EXIF_THUMBNAIL(3)

exif_thumbnail - Retrieve the embedded thumbnail of a TIFF or JPEG image

SYNOPSIS
string exif_thumbnail (string $filename, [int &$width], [int &$height], [int &$imagetype]) DESCRIPTION
exif_thumbnail(3) reads the embedded thumbnail of a TIFF or JPEG image. If you want to deliver thumbnails through this function, you should send the mimetype information using the header(3) function. It is possible that exif_thumbnail(3) cannot create an image but can determine its size. In this case, the return value is FALSE but $width and $height are set. PARAMETERS
o $filename - The name of the image file being read. This image contains an embedded thumbnail. o $width - The return width of the returned thumbnail. o $height - The returned height of the returned thumbnail. o $imagetype - The returned image type of the returned thumbnail. This is either TIFF or JPEG. RETURN VALUES
Returns the embedded thumbnail, or FALSE if the image contains no thumbnail. EXAMPLES
Example #1 exif_thumbnail(3) example <?php if (array_key_exists('file', $_REQUEST)) { $image = exif_thumbnail($_REQUEST['file'], $width, $height, $type); } else { $image = false; } if ($image!==false) { header('Content-type: ' .image_type_to_mime_type($type)); echo $image; exit; } else { // no thumbnail available, handle the error here echo 'No thumbnail available'; } ?> SEE ALSO
exif_read_data(3), image_type_to_mime_type(3). PHP Documentation Group EXIF_THUMBNAIL(3)
All times are GMT -4. The time now is 07:28 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy