unixcall.h

Go to the documentation of this file.
00001 /** @file rutz/unixcall.h thin wrappers around unix system calls */
00002 
00003 ///////////////////////////////////////////////////////////////////////
00004 //
00005 // Copyright (c) 1999-2004 California Institute of Technology
00006 // Copyright (c) 2004-2007 University of Southern California
00007 // Rob Peters <rjpeters at usc dot edu>
00008 //
00009 // created: Wed Nov 17 15:05:41 1999
00010 // commit: $Id: unixcall.h 8249 2007-04-12 06:03:40Z rjpeters $
00011 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/rutz/unixcall.h $
00012 //
00013 // --------------------------------------------------------------------
00014 //
00015 // This file is part of GroovX.
00016 //   [http://ilab.usc.edu/rjpeters/groovx/]
00017 //
00018 // GroovX is free software; you can redistribute it and/or modify it
00019 // under the terms of the GNU General Public License as published by
00020 // the Free Software Foundation; either version 2 of the License, or
00021 // (at your option) any later version.
00022 //
00023 // GroovX is distributed in the hope that it will be useful, but
00024 // WITHOUT ANY WARRANTY; without even the implied warranty of
00025 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00026 // General Public License for more details.
00027 //
00028 // You should have received a copy of the GNU General Public License
00029 // along with GroovX; if not, write to the Free Software Foundation,
00030 // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
00031 //
00032 ///////////////////////////////////////////////////////////////////////
00033 
00034 #ifndef GROOVX_RUTZ_UNIXCALL_H_UTC20050626084019_DEFINED
00035 #define GROOVX_RUTZ_UNIXCALL_H_UTC20050626084019_DEFINED
00036 
00037 #include <sys/types.h>
00038 #include <unistd.h>
00039 
00040 namespace rutz
00041 {
00042   class fstring;
00043 
00044   /// Wrappers of OS/system calls.
00045   namespace unixcall
00046   {
00047     /**  DESCRIPTION
00048          The mode of the file given by path is changed.
00049 
00050          Modes are specified by or'ing the following:
00051 
00052          ERRORS
00053          Throws a rutz::error on error if an error occurs. The more
00054          general errors for chmod are listed below:
00055 
00056          EPERM   The effective user id does not match the owner of  the
00057          file, and is not zero.
00058          EROFS   The named file resides on a read-only file system.
00059          EFAULT  path points outside your accessible address space.
00060          ENAMETOOLONG
00061          path is too long.
00062          ENOENT  The file does not exist.
00063          ENOMEM  Insufficient kernel memory was available.
00064          ENOTDIR A component of the path prefix is not a directory.
00065          EACCES  Search permission is denied on a component of  the
00066          path prefix.
00067          ELOOP   Too   many  symbolic  links  were  encountered  in
00068          resolving path.
00069          EIO     An I/O error occurred. */
00070     void chmod(const char* path, mode_t mode);
00071 
00072 
00073     /**  DESCRIPTION
00074          rename  renames  a  file, moving it between directories if
00075          required.
00076 
00077          Any other hard links to the file (as created  using  link)
00078          are unaffected.
00079 
00080          If  newpath already exists it will be atomically overwrit-
00081          ten (subject to a few conditions - see ERRORS  below),  so
00082          that there is no point at which another process attempting
00083          to access newpath will find it missing.
00084 
00085          If newpath exists but the operation fails for some  reason
00086          or  the  system  crashes  rename  guarantees  to  leave an
00087          instance of newpath in place.
00088 
00089          However, when overwriting there will probably be a  window
00090          in  which both oldpath and newpath refer to the file being
00091          renamed.
00092 
00093          If oldpath refers to a symbolic link the link is  renamed;
00094          if  newpath  refers  to  a  symbolic link the link will be
00095          overwritten.
00096 
00097          ERRORS
00098          Throws a rutz::error on error if an error occurs.
00099     */
00100     void rename(const char* oldpath, const char* newpath);
00101 
00102 
00103     /**  DESCRIPTION
00104          remove  deletes  a  name from the filesystem. If that name
00105          was the last link to a file and no processes have the file
00106          open  the  file  is  deleted and the space it was using is
00107          made available for reuse.
00108 
00109          If the name was the last link to a file but any  processes
00110          still have the file open the file will remain in existence
00111          until the last file descriptor referring to it is  closed.
00112 
00113          If  the  name  referred  to  a  symbolic  link the link is
00114          removed.
00115 
00116          If the name referred to a socket, fifo or device the  name
00117          for it is removed but processes which have the object open
00118          may continue to use it.
00119 
00120          ERRORS
00121          Throws a rutz::error on error if an error occurs.
00122     */
00123     void remove(const char* pathname);
00124 
00125     /// Get the absolute pathname of the current working directory.
00126     rutz::fstring getcwd();
00127 
00128     /// Check if any processes (other than self) are using the file.
00129     /** Returns the pid of the first process that has the file open,
00130         or 0 if no processes are using the file. */
00131     pid_t get_file_user_pid(const char* fname);
00132 
00133   } // end namespace unixcall
00134 
00135 } // end namespace rutz
00136 
00137 static const char __attribute__((used)) vcid_groovx_rutz_unixcall_h_utc20050626084019[] = "$Id: unixcall.h 8249 2007-04-12 06:03:40Z rjpeters $ $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/rutz/unixcall.h $";
00138 #endif // !GROOVX_RUTZ_UNIXCALL_H_UTC20050626084019_DEFINED
Generated on Sun May 8 08:06:44 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3