VirtualBox

Changeset 60373 in vbox for trunk/include/iprt


Ignore:
Timestamp:
Apr 7, 2016 2:21:30 PM (9 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
106457
Message:

Runtime/linux/sysfs.cpp: Convert RTLinuxSysFs* API to always use IPRT status codes instead of using errno and adapt all of its users

Location:
trunk/include/iprt
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/linux/sysfs.h

    r57004 r60373  
    55
    66/*
    7  * Copyright (C) 2008-2015 Oracle Corporation
     7 * Copyright (C) 2008-2016 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    4444 * Checks if a sysfs file (or directory, device, symlink, whatever) exists.
    4545 *
    46  * @returns true / false, errno is preserved.
     46 * @returns true if the sysfs object exists.
     47 *          false otherwise or if an error occurred.
    4748 * @param   pszFormat   The name format, either absolute or relative to "/sys/".
    4849 * @param   va          The format args.
     
    5152
    5253/**
     54 * Checks if a sysfs object (directory, device, symlink, whatever) exists.
     55 *
     56 * @returns IPRT status code.
     57 * @retval  VINF_SUCCESS if the sysfs object exists.
     58 * @retval  VERR_FILE_NOT_FOUND if the sysfs object does not exist.
     59 * @param   pszFormat   The name format, either absolute or relative to "/sys/".
     60 * @param   va          The format args.
     61 */
     62RTDECL(int) RTLinuxSysFsExistsExV(const char *pszFormat, va_list va)  RT_IPRT_FORMAT_ATTR(1, 0);
     63
     64/**
    5365 * Checks if a sysfs file (or directory, device, symlink, whatever) exists.
    5466 *
    55  * @returns true / false, errno is preserved.
     67 * @returns true if the sysfs object exists.
     68 *          false otherwise or if an error occurred.
    5669 * @param   pszFormat   The name format, either absolute or relative to "/sys/".
    5770 * @param   ...         The format args.
     
    6073
    6174/**
     75 * Checks if a sysfs object (directory, device, symlink, whatever) exists.
     76 *
     77 * @returns IPRT status code.
     78 * @retval  VINF_SUCCESS if the sysfs object exists.
     79 * @retval  VERR_FILE_NOT_FOUND if the sysfs object does not exist.
     80 * @param   pszFormat   The name format, either absolute or relative to "/sys/".
     81 * @param   ...         The format args.
     82 */
     83RTDECL(int) RTLinuxSysFsExistsEx(const char *pszFormat, ...)  RT_IPRT_FORMAT_ATTR(1, 2);
     84
     85/**
    6286 * Opens a sysfs file.
    6387 *
    64  * @returns The file descriptor. -1 and errno on failure.
     88 * @returns IPRT status code.
     89 * @param   phFile      Where to store the file handle on success.
    6590 * @param   pszFormat   The name format, either absolute or relative to "/sys/".
    6691 * @param   va          The format args.
    67  */
    68 RTDECL(int) RTLinuxSysFsOpenV(const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(1, 0);
     92 *
     93 * @note Close the file using RTFileClose().
     94 */
     95RTDECL(int) RTLinuxSysFsOpenV(PRTFILE phFile, const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(1, 0);
    6996
    7097/**
    7198 * Opens a sysfs file.
    7299 *
    73  * @returns The file descriptor. -1 and errno on failure.
     100 * @returns IPRT status code.
     101 * @param   phFile      Where to store the file handle on success.
    74102 * @param   pszFormat   The name format, either absolute or relative to "/sys/".
    75103 * @param   ...         The format args.
    76  */
    77 RTDECL(int) RTLinuxSysFsOpen(const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(1, 2);
    78 
    79 /**
    80  * Closes a file opened with RTLinuxSysFsOpen or RTLinuxSysFsOpenV.
    81  *
    82  * @param   fd          File descriptor returned by RTLinuxSysFsOpen or
    83  *                      RTLinuxSysFsOpenV.
    84  */
    85 RTDECL(void) RTLinuxSysFsClose(int fd);
     104 *
     105 * @note Close the file using RTFileClose().
     106 */
     107RTDECL(int) RTLinuxSysFsOpen(PRTFILE phFile, const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(1, 2);
    86108
    87109/**
    88110 * Reads a string from a file opened with RTLinuxSysFsOpen or RTLinuxSysFsOpenV.
    89111 *
    90  * @returns The number of bytes read. -1 and errno on failure.
    91  * @param   fd          The file descriptor returned by RTLinuxSysFsOpen or RTLinuxSysFsOpenV.
     112 * @returns IPRT status code.
     113 * @param   hFile       The file descriptor returned by RTLinuxSysFsOpen or RTLinuxSysFsOpenV.
    92114 * @param   pszBuf      Where to store the string.
    93115 * @param   cchBuf      The size of the buffer. Must be at least 2 bytes.
    94  */
    95 RTDECL(ssize_t) RTLinuxSysFsReadStr(int fd, char *pszBuf, size_t cchBuf);
     116 * @param   pcchRead    Where to store the amount of characters read on success - optional.
     117 */
     118RTDECL(int) RTLinuxSysFsReadStr(RTFILE hFile, char *pszBuf, size_t cchBuf, size_t *pcchRead);
    96119
    97120/**
     
    100123 *
    101124 * @returns IPRT status code.
    102  * @param   fd          The file descriptor returned by RTLinuxSysFsOpen or RTLinuxSysFsOpenV.
     125 * @param   hFile       The file descriptor returned by RTLinuxSysFsOpen or RTLinuxSysFsOpenV.
    103126 * @param   pvBuf       Where to store the bits from the file.
    104127 * @param   cbBuf       The size of the buffer.
    105128 * @param   pcbRead     Where to return the number of bytes read.  Optional.
    106129 */
    107 RTDECL(int) RTLinuxSysFsReadFile(int fd, void *pvBuf, size_t cbBuf, size_t *pcbRead);
     130RTDECL(int) RTLinuxSysFsReadFile(RTFILE hFile, void *pvBuf, size_t cbBuf, size_t *pcbRead);
    108131
    109132/**
    110133 * Reads a number from a sysfs file.
    111134 *
    112  * @returns 64-bit signed value on success, -1 and errno on failure.
     135 * @returns IPRT status code.
    113136 * @param   uBase       The number base, 0 for autodetect.
     137 * @param   pi64        Where to store the 64-bit signed on success.
    114138 * @param   pszFormat   The filename format, either absolute or relative to "/sys/".
    115139 * @param   va          Format args.
    116140 */
    117 RTDECL(int64_t) RTLinuxSysFsReadIntFileV(unsigned uBase, const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(2, 0);
     141RTDECL(int) RTLinuxSysFsReadIntFileV(unsigned uBase, int64_t *pi64, const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(2, 0);
    118142
    119143/**
    120144 * Reads a number from a sysfs file.
    121145 *
    122  * @returns 64-bit signed value on success, -1 and errno on failure.
     146 * @returns IPRT status code.
    123147 * @param   uBase       The number base, 0 for autodetect.
    124  * @param   pszFormat   The filename format, either absolute or relative to "/sys/".
    125  * @param   ...         Format args.
    126  */
    127 RTDECL(int64_t) RTLinuxSysFsReadIntFile(unsigned uBase, const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(2, 3);
     148 * @param   pi64        Where to store the 64-bit signed on success.
     149 * @param   pszFormat   The filename format, either absolute or relative to "/sys/".
     150 * @param   ...         Format args.
     151 */
     152RTDECL(int) RTLinuxSysFsReadIntFile(unsigned uBase, int64_t *pi64, const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(2, 3);
    128153
    129154/**
    130155 * Reads a device number from a sysfs file.
    131156 *
    132  * @returns device number on success, 0 and errno on failure.
     157 * @returns IPRT status code.
     158 * @param   pDevNum     Where to store the device number on success.
    133159 * @param   pszFormat   The filename format, either absolute or relative to "/sys/".
    134160 * @param   va          Format args.
    135161 */
    136 RTDECL(dev_t) RTLinuxSysFsReadDevNumFileV(const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(1, 0);
     162RTDECL(int) RTLinuxSysFsReadDevNumFileV(dev_t *pDevNum, const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(1, 0);
    137163
    138164/**
    139165 * Reads a device number from a sysfs file.
    140166 *
    141  * @returns device number on success, 0 and errno on failure.
    142  * @param   pszFormat   The filename format, either absolute or relative to "/sys/".
    143  * @param   ...         Format args.
    144  */
    145 RTDECL(dev_t) RTLinuxSysFsReadDevNumFile(const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(1, 2);
     167 * @returns IPRT status code.
     168 * @param   pDevNum     Where to store the device number on success.
     169 * @param   pszFormat   The filename format, either absolute or relative to "/sys/".
     170 * @param   ...         Format args.
     171 */
     172RTDECL(int) RTLinuxSysFsReadDevNumFile(dev_t *pDevNum, const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(1, 2);
    146173
    147174/**
     
    149176 * return the text up until there.
    150177 *
    151  * @returns number of characters read on success, -1 and errno on failure.
    152  * @param   pszBuf      Where to store the path element.  Must be at least two
    153  *                      characters, but a longer buffer would be advisable.
    154  * @param   cchBuf      The size of the buffer pointed to by @a pszBuf.
     178 * @returns IPRT status code.
     179 * @param   pszBuf      Where to store the path element.  Must be at least two
     180 *                      characters, but a longer buffer would be advisable.
     181 * @param   cchBuf      The size of the buffer pointed to by @a pszBuf.
     182 * @param   pcchRead    Where to store the amount of characters read on success - optional.
    155183 * @param   pszFormat   The filename format, either absolute or relative to "/sys/".
    156184 * @param   va          Format args.
    157185 */
    158 RTDECL(ssize_t) RTLinuxSysFsReadStrFileV(char *pszBuf, size_t cchBuf, const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(3, 0);
     186RTDECL(int) RTLinuxSysFsReadStrFileV(char *pszBuf, size_t cchBuf, size_t *pcchRead, const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(3, 0);
    159187
    160188/**
     
    162190 * return the text up until there.
    163191 *
    164  * @returns number of characters read on success, -1 and errno on failure.
    165  * @param   pszBuf      Where to store the path element.  Must be at least two
    166  *                      characters, but a longer buffer would be advisable.
    167  * @param   cchBuf      The size of the buffer pointed to by @a pszBuf.
    168  * @param   pszFormat   The filename format, either absolute or relative to "/sys/".
    169  * @param   ...         Format args.
    170  */
    171 RTDECL(ssize_t) RTLinuxSysFsReadStrFile(char *pszBuf, size_t cchBuf, const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(3, 4);
     192 * @returns IPRT status code.
     193 * @param   pszBuf      Where to store the path element.  Must be at least two
     194 *                      characters, but a longer buffer would be advisable.
     195 * @param   cchBuf      The size of the buffer pointed to by @a pszBuf.
     196 * @param   pcchRead    Where to store the amount of characters read on success - optional.
     197 * @param   pszFormat   The filename format, either absolute or relative to "/sys/".
     198 * @param   ...         Format args.
     199 */
     200RTDECL(int) RTLinuxSysFsReadStrFile(char *pszBuf, size_t cchBuf, size_t *pcchRead, const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(3, 4);
    172201
    173202/**
     
    179208 * directory.
    180209 *
    181  * @returns The length of the returned string on success, -1 and errno on
    182  *          failure.
    183  * @param   pszBuf      Where to store the path element.  Must be at least two
    184  *                      characters, but a longer buffer would be advisable.
    185  * @param   cchBuf      The size of the buffer pointed to by @a pszBuf.
     210 * @returns IPRT status code.
     211 * @param   pszBuf      Where to store the path element.  Must be at least two
     212 *                      characters, but a longer buffer would be advisable.
     213 * @param   cchBuf      The size of the buffer pointed to by @a pszBuf.
     214 * @param   pchBuf      Where to store the length of the returned string on success - optional.
    186215 * @param   pszFormat   The filename format, either absolute or relative to "/sys/".
    187216 * @param   va           Format args.
    188217 */
    189 RTDECL(ssize_t) RTLinuxSysFsGetLinkDestV(char *pszBuf, size_t cchBuf, const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(3, 0);
     218RTDECL(int) RTLinuxSysFsGetLinkDestV(char *pszBuf, size_t cchBuf, size_t *pchBuf, const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(3, 0);
    190219
    191220/**
     
    197226 * directory.
    198227 *
    199  * @returns The length of the returned string on success, -1 and errno on
    200  *          failure.
    201  * @param   pszBuf      Where to store the path element.  Must be at least two
    202  *                      characters, but a longer buffer would be advisable.
    203  * @param   cchBuf      The size of the buffer pointed to by @a pszBuf.
    204  * @param   pszFormat   The filename format, either absolute or relative to "/sys/".
    205  * @param   ...         Format args.
    206  */
    207 RTDECL(ssize_t) RTLinuxSysFsGetLinkDest(char *pszBuf, size_t cchBuf, const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(3, 4);
     228 * @returns IPRT status code.
     229 * @param   pszBuf      Where to store the path element.  Must be at least two
     230 *                      characters, but a longer buffer would be advisable.
     231 * @param   cchBuf      The size of the buffer pointed to by @a pszBuf.
     232 * @param   pchBuf      Where to store the length of the returned string on success - optional.
     233 * @param   pszFormat   The filename format, either absolute or relative to "/sys/".
     234 * @param   ...         Format args.
     235 */
     236RTDECL(int) RTLinuxSysFsGetLinkDest(char *pszBuf, size_t cchBuf, size_t *pchBuf, const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(3, 4);
    208237
    209238/**
     
    211240 * pattern and store the path into @a pszBuf.
    212241 *
    213  * @returns The length of the returned string on success, -1 and errno on
    214  *          failure.
    215  * @returns -1 and ENOENT if no matching device node could be found.
     242 * @returns IPRT status code.
     243 * @retval  VERR_FILE_NOT_FOUND if no matching device node could be found.
    216244 * @param   DevNum         The device number to search for.
    217245 * @param   fMode          The type of device - only RTFS_TYPE_DEV_CHAR and
     
    223251 * @param   va             Format args.
    224252 */
    225 RTDECL(ssize_t) RTLinuxCheckDevicePathV(dev_t DevNum, RTFMODE fMode, char *pszBuf, size_t cchBuf,
    226                                         const char *pszPattern, va_list va) RT_IPRT_FORMAT_ATTR(5, 0);
     253RTDECL(int) RTLinuxCheckDevicePathV(dev_t DevNum, RTFMODE fMode, char *pszBuf, size_t cchBuf,
     254                                    const char *pszPattern, va_list va) RT_IPRT_FORMAT_ATTR(5, 0);
    227255
    228256/**
     
    230258 * pattern and store the path into @a pszBuf.
    231259 *
    232  * @returns The length of the returned string on success, -1 and errno on
    233  *          failure.
    234  * @returns -1 and ENOENT if no matching device node could be found.
     260 * @returns IPRT status code.
     261 * @retval  VERR_FILE_NOT_FOUND if no matching device node could be found.
    235262 * @param   DevNum          The device number to search for
    236263 * @param   fMode           The type of device - only RTFS_TYPE_DEV_CHAR and
     
    242269 * @param   ...             Format args.
    243270 */
    244 RTDECL(ssize_t) RTLinuxCheckDevicePath(dev_t DevNum, RTFMODE fMode, char *pszBuf, size_t cchBuf,
    245                                        const char *pszPattern, ...) RT_IPRT_FORMAT_ATTR(5, 6);
     271RTDECL(int) RTLinuxCheckDevicePath(dev_t DevNum, RTFMODE fMode, char *pszBuf, size_t cchBuf,
     272                                   const char *pszPattern, ...) RT_IPRT_FORMAT_ATTR(5, 6);
    246273
    247274/** @} */
  • trunk/include/iprt/mangling.h

    r60245 r60373  
    996996# define RTLinuxSysFsClose                              RT_MANGLER(RTLinuxSysFsClose)
    997997# define RTLinuxSysFsExists                             RT_MANGLER(RTLinuxSysFsExists)
     998# define RTLinuxSysFsExistsEx                           RT_MANGLER(RTLinuxSysFsExistsEx)
     999# define RTLinuxSysFsExistsExV                           RT_MANGLER(RTLinuxSysFsExistsExV)
    9981000# define RTLinuxSysFsExistsV                            RT_MANGLER(RTLinuxSysFsExistsV)
    9991001# define RTLinuxSysFsGetLinkDest                        RT_MANGLER(RTLinuxSysFsGetLinkDest)
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette