title: Reading a file into a string buffer in python
body: <p>The following is a simplfied version of code that used to work until recently. I am trying to read a text file into a string buffer using the libc6 read function:</p>
  
  <pre><code>import ctypes, os
  from ctypes import *
  
  libc = CDLL('libc.so.6', use_errno = True)
  
  f=os.open('test.txt', os.O_RDONLY)
  if f &lt; 0:
      print 'Cannot open file'
  
  buf = create_string_buffer(10)
  buf_ptr = ctypes.addressof(buf)
  
  print libc.read(f, buf_ptr, 5)
  e = get_errno()
  print str(e) + ': ' + os.strerror(e)
  print repr(buf.raw)
  </code></pre>
  
  <p>The output has an error</p>
  
  <pre><code>&gt;&gt; -1
  &gt;&gt; 14: Bad address
  &gt;&gt; '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
  </code></pre>
  
  <p>What is going on, what am I missing? Just to be sure, I coded this in C as well and it works just fine. Any suggestions?</p>
  
  <p>EDIT: It might be worth mentioning that the code this came from reads directly from a drive into a memory aligned buffer. That code worked fine for years and suddenly doesn't anymore.</p>
  
  <p>EDIT 1: OK, I correctly checked the error that <code>read</code> throws. It is related to the buffer, but I can't figure out what it is (I don't get it in C and there should be no alignment requirements).</p>