• Main Page
  • Modules
  • Data Structures
  • Files
  • File List
  • Globals

ext/fcntl/fcntl.c

Go to the documentation of this file.
00001 /************************************************
00002 
00003   fcntl.c -
00004 
00005   $Author: nobu $
00006   created at: Mon Apr  7 18:53:05 JST 1997
00007 
00008   Copyright (C) 1997-2001 Yukihiro Matsumoto
00009 
00010 ************************************************/
00011 
00012 /************************************************
00013 = NAME
00014 
00015 fcntl - load the C fcntl.h defines
00016 
00017 = SYNOPSIS
00018 
00019     require "fcntl"
00020     m = s.fcntl(Fcntl::F_GETFL, 0)
00021     f.fcntl(Fcntl::F_SETFL, Fcntl::O_NONBLOCK|m)
00022 
00023 = DESCRIPTION
00024 
00025 This module is just a translation of the C <fcntl.h> file.
00026 
00027 = NOTE
00028 
00029 Only #define symbols get translated; you must still correctly
00030 pack up your own arguments to pass as args for locking functions, etc.
00031 
00032 ************************************************/
00033 
00034 #include "ruby.h"
00035 #include <fcntl.h>
00036 
00037 /* Fcntl loads the constants defined in the system's <fcntl.h> C header
00038  * file, and used with both the fcntl(2) and open(2) POSIX system calls.
00039  *
00040  * Copyright (C) 1997-2001 Yukihiro Matsumoto
00041  *
00042  * Documented by mathew <meta@pobox.com>
00043  *
00044  * = Usage
00045  *
00046  * To perform a fcntl(2) operation, use IO::fcntl in the core classes.
00047  *
00048  * To perform an open(2) operation, use IO::sysopen.
00049  *
00050  * The set of operations and constants available depends upon specific OS
00051  * platform. Some values listed below may not be supported on your system.
00052  *
00053  * The constants supported by Ruby for use with IO::fcntl are:
00054  *
00055  * - F_DUPFD - duplicate a close-on-exec file handle to a non-close-on-exec
00056  *   file handle.
00057  *
00058  * - F_GETFD - read the close-on-exec flag of a file handle.
00059  *
00060  * - F_SETFD - set the close-on-exec flag of a file handle.
00061  *
00062  * - FD_CLOEXEC - the value of the close-on-exec flag.
00063  *
00064  * - F_GETFL - get file descriptor flags.
00065  *
00066  * - F_SETFL - set file descriptor flags.
00067  *
00068  * - O_APPEND, O_NONBLOCK, etc (see below) - file descriptor flag
00069  *   values for the above.
00070  *
00071  * - F_GETLK - determine whether a given region of a file is locked.
00072  *
00073  * - F_SETLK - acquire a lock on a region of a file.
00074  *
00075  * - F_SETLKW - acquire a lock on a region of a file, waiting if necessary.
00076  *
00077  * - F_RDLCK, F_WRLCK, F_UNLCK - types of lock for the above.
00078  *
00079  * The constants supported by Ruby for use with IO::sysopen are:
00080  *
00081  * - O_APPEND - open file in append mode.
00082  *
00083  * - O_NOCTTY - open tty without it becoming controlling tty.
00084  *
00085  * - O_CREAT - create file if it doesn't exist.
00086  *
00087  * - O_EXCL - used with O_CREAT, fail if file exists.
00088  *
00089  * - O_TRUNC - truncate file on open.
00090  *
00091  * - O_NONBLOCK / O_NDELAY - open in non-blocking mode.
00092  *
00093  * - O_RDONLY - open read-only.
00094  *
00095  * - O_WRONLY - open write-only.
00096  *
00097  * - O_RDWR - open read-write.
00098  *
00099  * - O_ACCMODE - mask to extract read/write flags.
00100  *
00101  * Example:
00102  *
00103  *   require 'fcntl'
00104  *
00105  *   fd = IO::sysopen('/tmp/tempfile',
00106  *        Fcntl::O_WRONLY | Fcntl::O_EXCL | Fcntl::O_CREAT)
00107  *   f = IO.open(fd)
00108  *   f.syswrite("TEMP DATA")
00109  *   f.close
00110  *
00111  */
00112 void
00113 Init_fcntl()
00114 {
00115     VALUE mFcntl = rb_define_module("Fcntl");
00116 #ifdef F_DUPFD
00117     rb_define_const(mFcntl, "F_DUPFD", INT2NUM(F_DUPFD));
00118 #endif
00119 #ifdef F_GETFD
00120     rb_define_const(mFcntl, "F_GETFD", INT2NUM(F_GETFD));
00121 #endif
00122 #ifdef F_GETLK
00123     rb_define_const(mFcntl, "F_GETLK", INT2NUM(F_GETLK));
00124 #endif
00125 #ifdef F_SETFD
00126     rb_define_const(mFcntl, "F_SETFD", INT2NUM(F_SETFD));
00127 #endif
00128 #ifdef F_GETFL
00129     rb_define_const(mFcntl, "F_GETFL", INT2NUM(F_GETFL));
00130 #endif
00131 #ifdef F_SETFL
00132     rb_define_const(mFcntl, "F_SETFL", INT2NUM(F_SETFL));
00133 #endif
00134 #ifdef F_SETLK
00135     rb_define_const(mFcntl, "F_SETLK", INT2NUM(F_SETLK));
00136 #endif
00137 #ifdef F_SETLKW
00138     rb_define_const(mFcntl, "F_SETLKW", INT2NUM(F_SETLKW));
00139 #endif
00140 #ifdef FD_CLOEXEC
00141     rb_define_const(mFcntl, "FD_CLOEXEC", INT2NUM(FD_CLOEXEC));
00142 #endif
00143 #ifdef F_RDLCK
00144     rb_define_const(mFcntl, "F_RDLCK", INT2NUM(F_RDLCK));
00145 #endif
00146 #ifdef F_UNLCK
00147     rb_define_const(mFcntl, "F_UNLCK", INT2NUM(F_UNLCK));
00148 #endif
00149 #ifdef F_WRLCK
00150     rb_define_const(mFcntl, "F_WRLCK", INT2NUM(F_WRLCK));
00151 #endif
00152 #ifdef O_CREAT
00153     rb_define_const(mFcntl, "O_CREAT", INT2NUM(O_CREAT));
00154 #endif
00155 #ifdef O_EXCL
00156     rb_define_const(mFcntl, "O_EXCL", INT2NUM(O_EXCL));
00157 #endif
00158 #ifdef O_NOCTTY
00159     rb_define_const(mFcntl, "O_NOCTTY", INT2NUM(O_NOCTTY));
00160 #endif
00161 #ifdef O_TRUNC
00162     rb_define_const(mFcntl, "O_TRUNC", INT2NUM(O_TRUNC));
00163 #endif
00164 #ifdef O_APPEND
00165     rb_define_const(mFcntl, "O_APPEND", INT2NUM(O_APPEND));
00166 #endif
00167 #ifdef O_NONBLOCK
00168     rb_define_const(mFcntl, "O_NONBLOCK", INT2NUM(O_NONBLOCK));
00169 #endif
00170 #ifdef O_NDELAY
00171     rb_define_const(mFcntl, "O_NDELAY", INT2NUM(O_NDELAY));
00172 #endif
00173 #ifdef O_RDONLY
00174     rb_define_const(mFcntl, "O_RDONLY", INT2NUM(O_RDONLY));
00175 #endif
00176 #ifdef O_RDWR
00177     rb_define_const(mFcntl, "O_RDWR", INT2NUM(O_RDWR));
00178 #endif
00179 #ifdef O_WRONLY
00180     rb_define_const(mFcntl, "O_WRONLY", INT2NUM(O_WRONLY));
00181 #endif
00182 #ifdef O_ACCMODE
00183     rb_define_const(mFcntl, "O_ACCMODE", INT2FIX(O_ACCMODE));
00184 #else
00185     rb_define_const(mFcntl, "O_ACCMODE", INT2FIX(O_RDONLY | O_WRONLY | O_RDWR));
00186 #endif
00187 }
00188 

Generated on Sat Jul 7 2012 15:29:08 for Ruby by  doxygen 1.7.1