title: How to combine ppm image files in C using only system calls?
body: <p>I've found some similar questions on the internet, but not with system calls.</p>
  
  <p>I'm doing an exercise in my system programming class. It asks you to combine ppm image files in binary form(<code>P6</code>, not <code>P3</code>) using only system calls. Input is taken from command line. The first input is the larger image file, the second input is the smaller image file, and after the inputs the files are combined and written into a third file, which you can specify the name of as a third input. The smaller file is written into the top-right of the larger file.</p>
  
  <p>Since we're using system calls, I'm assuming we're mainly using <code>open/read/write/lseek</code>. I know that my ppm files will store the magic number <code>P6</code> at the beginning, and then the width and height of the file. I know that I can use <code>lseek</code> by writing from the left side of row 1 of the larger ppm file, then stopping when my pointer reaches the difference in size between the two files, and writing the remaining pixels for the line from the smaller file. Then continuing, line by line...</p>
  
  <p>However, I have no idea how to implement this. I'm not sure how to even read the width and height of the file, either. I'm sort of lost. <em>Can someone help me get on the right track?</em> I'd post my code if I actually had anything meaningful, but I just created file descriptors for the files and opened them so far. </p>
  
  <p>EDIT:</p>
  
  <p>I combine them by overwriting the top right of the larger file with the smaller file. I'm not guaranteed anything about the images, so I have to somehow pull the width and height from both files and compare them, to make sure the first file has both a larger width and height than the second.</p>
  
  <p>I think they want us to loop through the files, pixel by pixel, reading each rgb group of values for each pixel using <code>read</code>. Then writing in a loop, pixel by pixel, using <code>write</code>.</p>
  
  <p>EDIT2: </p>
  
  <p>Here's a list of unix system calls. They're available in the c library, but this is all I'm allowed to use: <a href="http://www.di.uevora.pt/~lmr/syscalls.html" rel="nofollow noreferrer">http://www.di.uevora.pt/~lmr/syscalls.html</a></p>