<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/143937>143937</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [libc] avoid setting errno in `src/__support`
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            libc
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          michaelrj-google
      </td>
    </tr>
</table>

<pre>
    Setting errno in support makes controlling whether errno is set much more difficult. Errno should be set as close to the return of a public function as possible.

List of places that need to be changed:
- [ ] [__support/OSUtil/linux/fcntl.cpp](https://github.com/llvm/llvm-project/blob/main/libc/src/__support/OSUtil/linux/fcntl.cpp) - change to returning `ErrorOr` since if there's an error it always returns -1.
- [ ] [__support/OSUtil/linux/vdso.cpp](https://github.com/llvm/llvm-project/blob/main/libc/src/__support/OSUtil/linux/vdso.cpp) - currently calling public functions in support, which is also a problem. Move `getauxval` to an internal utility that doesn't set errno and this problem goes away.
- [ ] [__support/HashTable/randomness.h](https://github.com/llvm/llvm-project/blob/main/libc/src/__support/HashTable/randomness.h) - same issue as vdso, calling public functions leads to setting errno.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzElD-P3DYQxT8N1QxOkLj6cypU2DkLKRK4cFIbI3Ik0qFIgUPteb99QO1d4hhwEBeBG7F5fDPz49Mgs1090Sjat6J9KvBIJsRxs8ogufjpYQ1hdVTMQd_GD5SS9StQjD6A9cDHvoeYYMM_iEEFn2JwLkueDSVD8VXKwJRgO5SBLUQCbZfFqsOlEt6dCjbhcBpmOoXIoFxgghQgGYJI6YgewgII-zE7q2A5vEo2-KzdA7OdHZWieiOqN79YTlm7O1TEkAwm8EQ6u80EyqBfSYtL1j6AaN-CaJ_y-fHjy0BCTu8__J6sE3Jy1h-fhZwW5ZMr1b6L9knIR5PSztlDTkJOq03mmEsVtnzDXV-Phz2GT6Sy4ezCLOS0ofWn66yEnDjm73-sKwd4eOk-j3KHkmGLrnoXY4jvo-gqYOsVgV0yuUhC9gzo80OECDYBume88ctthoe6_C4MV83hB1D4q-wdwhEj-eRuoPCet69SwV-kU8if4NlYZXIM0XHIIYphdrSV8Gu4Uua3UsLj8xVdJphCJmZ9oujRwZGss-l2D5IOxF7IPp1BvccbvYZkLL_awhqIAZ_x9q9sf0Y2v-HsSMgpotdh88Rcmv8X7TernmQZNwLLfFD-sTL1jO-blB2h5syLv1wNZaHHix4uAxY01n0z9M1j27eFGbtaV5ehexxmvXTz0rSXoW2GVmMvF8K6L-woK9lWXS3rvu7qprxQLVE3alC6qruuFU1FG1pX5unLENfi7Hasm8tw6QuHMzk-t5mUdwYy77U4nrTmY2XRVM5y4r8dkk3u3IDnhfYJ8Bqs_udMOVCiq77m2VXFEd343Y91Ns1CTi99X0f5ZwAAAP__fyrb8Q">