title: (open + write) vs. (fopen + fwrite) to kernel /proc/
body: <p>I have a very strange bug. If I do:</p>
  
  <pre><code>    int fd = open("/proc/...", O_WRONLY);
      write(fd, argv[1], strlen(argv[1]));
      close(fd);
  </code></pre>
  
  <p>everything is working including for a very long string which length > 1024.</p>
  
  <p>If I do:</p>
  
  <pre><code>    FILE *fd = fopen("/proc/...", "wb");
      fwrite(argv[1], 1, strlen(argv[1]), fd);
      fclose(fd);
  </code></pre>
  
  <p>the string is cut around 1024 characters.</p>
  
  <p>I'm running an ARM embedded device with a 3.4 kernel. I have debugged in the kernel and I see that the string is already cut when I reach the very early function vfs_write (I spotted this function with a WARN_ON instruction to get the stack).</p>
  
  <p>The problem is the same with fputs vs. puts.</p>
  
  <p>I can use fwrite for a very long string (>1024) if I write to a standard rootfs file. So the problem is really linked how the kernel handles /proc.</p>
  
  <p>Any idea what's going on?</p>