in reply to Bad File Descriptors Gone Wild
Be sure that you're checking the return value from your open call so that you're sure STOCK was, in fact, opened.