Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 27 Feb 2008 19:02:03 +0000 (UTC)
From:      John Baldwin <jhb@FreeBSD.org>
To:        src-committers@FreeBSD.org, cvs-src@FreeBSD.org, cvs-all@FreeBSD.org
Subject:   cvs commit: src/lib/libc/stdio fdopen.c fopen.c freopen.c
Message-ID:  <200802271902.m1RJ23wd012246@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
jhb         2008-02-27 19:02:02 UTC

  FreeBSD src repository

  Modified files:
    lib/libc/stdio       fdopen.c fopen.c freopen.c 
  Log:
  File descriptors are an int, but our stdio FILE object uses a short to hold
  them.  Thus, any fd whose value is greater than SHRT_MAX is handled
  incorrectly (the short value is sign-extended when converted to an int).
  An unpleasant side effect is that if fopen() opens a file and gets a
  backing fd that is greater than SHRT_MAX, fclose() will fail and the file
  descriptor will be leaked.  Better handle this by fixing fopen(), fdopen(),
  and freopen() to fail attempts to use a fd greater than SHRT_MAX with
  EMFILE.
  
  At some point in the future we should look at expanding the file descriptor
  in FILE to an int, but that is a bit complicated due to ABI issues.
  
  MFC after:      1 week
  Discussed on:   arch
  Reviewed by:    wollman
  
  Revision  Changes    Path
  1.9       +12 -0     src/lib/libc/stdio/fdopen.c
  1.12      +13 -0     src/lib/libc/stdio/fopen.c
  1.19      +14 -0     src/lib/libc/stdio/freopen.c



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200802271902.m1RJ23wd012246>