misc.h

Go to the documentation of this file.
00001 // Copyright (C) 2006-2007 Benedikt Böhm <hollow@gentoo.org>
00002 //
00003 // This program is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU General Public License
00005 // as published by the Free Software Foundation; either version 2
00006 // of the License, or (at your option) any later version.
00007 //
00008 // This program is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011 // GNU General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU General Public License
00014 // along with this program; if not, write to the Free Software
00015 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
00016 
00017 /*!
00018  * @defgroup misc Miscellaneous helpers
00019  *
00020  * The misc family of functions provide wrappers not fitting in any other
00021  * module and not being worth an own category for each of them.
00022  *
00023  * The isdir(), isfile() and islink() functions wrap the stat(2) system call and
00024  * checks if the path in the string pointed to by path is a directory, regular
00025  * file or link, respectively.
00026  *
00027  * The mkdirp() function creates any missing parent directories of the path in
00028  * the string pointed to by path, before creating the directory itself. The
00029  * mkdirnamep() function additionally calls dirname(3) on the path string
00030  * before calling mkdirp().
00031  *
00032  * The path_concat() function concatenates the strings pointed to by dirname and
00033  * basename and checks the latter using str_path_isdot().
00034  *
00035  * The runlink() function removes all files and directories in the path pointed
00036  * to by the string path.
00037  *
00038  * @{
00039  */
00040 
00041 #ifndef _LUCID_MISC_H
00042 #define _LUCID_MISC_H
00043 
00044 #include <sys/types.h>
00045 
00046 /*!
00047  * @brief check if given path exists
00048  *
00049  * @param[in] path path to check
00050  *
00051  * @return 1 on success, 0 otherwise
00052  *
00053  * @see stat(2)
00054  */
00055 int ispath(const char *path);
00056 
00057 /*!
00058  * @brief check if given path is a directory
00059  *
00060  * @param[in] path path to check
00061  *
00062  * @return 1 on success, 0 otherwise
00063  *
00064  * @see stat(2)
00065  */
00066 int isdir(const char *path);
00067 
00068 /*!
00069  * @brief check if given path is a regular file
00070  *
00071  * @param[in] path path to check
00072  *
00073  * @return 1 on success, 0 otherwise
00074  *
00075  * @see stat(2)
00076  */
00077 int isfile(const char *path);
00078 
00079 /*!
00080  * @brief check if given path is a symbolic link
00081  *
00082  * @param[in] path path to check
00083  *
00084  * @return 1 on success, 0 otherwise
00085  *
00086  * @see stat(2)
00087  */
00088 int islink(const char *path);
00089 
00090 /*!
00091  * @brief check if given path is a top-level mount point
00092  *
00093  * @param[in] path path to check
00094  *
00095  * @return 1 on success, 0 otherwise
00096  *
00097  * @see stat(2)
00098  */
00099 int ismount(const char *path);
00100 
00101 /*!
00102  * @brief recursive mkdir(2) with dirname(3)
00103  *
00104  * @param[in] path path to create
00105  * @param[in] mode file permissions
00106  *
00107  * @return 0 on success, -1 on error with errno set
00108  *
00109  * @see mkdir(2)
00110  * @see dirname(3)
00111  */
00112 int mkdirnamep(const char *path, mode_t mode);
00113 
00114 /*!
00115  * @brief recursive mkdir(2)
00116  *
00117  * @param[in] path path to create
00118  * @param[in] mode file permissions
00119  *
00120  * @return 0 on success, -1 on error with errno set
00121  *
00122  * @see mkdir(2)
00123  */
00124 int mkdirp(const char *path, mode_t mode);
00125 
00126 /*!
00127  * @brief recursive unlink(2) and rmdir(2)
00128  *
00129  * @param[in] path path to remove
00130  *
00131  * @return 0 on success, -1 on error with errno set
00132  *
00133  * @see unlink(2)
00134  * @see rmdir(2)
00135  */
00136 int runlink(const char *path);
00137 
00138 /*!
00139  * @brief read contents of symlink
00140  *
00141  * @param[in] path symlink to read
00142  *
00143  * @return on success a pointer to a string containing the destination of the
00144  *         link, NULL on error with errno set
00145  *
00146  * @see unlink(2)
00147  * @see rmdir(2)
00148  */
00149 char *readsymlink(const char *path);
00150 
00151 /*!
00152  * @brief copy a file
00153  *
00154  * @param[in] srcfd filedescriptor to read from
00155  * @param[in] dstfd filedescriptor to write to
00156  *
00157  * @return 0 on success, -1 on error with errno set
00158  */
00159 int copy_file(int srcfd, int dstfd);
00160 
00161 #endif
00162 
00163 /*! @} misc */

Generated on Tue Jun 19 20:38:26 2007 for lucid by  doxygen 1.5.2