stdlib.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. *
  8. * 1. Redistributions of source code must retain the above copyright notice, this
  9. * list of conditions and the following disclaimer.
  10. *
  11. * 2. Redistributions in binary form must reproduce the above copyright notice,
  12. * this list of conditions and the following disclaimer in the documentation
  13. * and/or other materials provided with the distribution.
  14. *
  15. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  16. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  17. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  18. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  19. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  20. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  21. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  22. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  23. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  24. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. */
  26. #include <AK/Assertions.h>
  27. #include <AK/HashMap.h>
  28. #include <AK/StdLibExtras.h>
  29. #include <AK/Types.h>
  30. #include <AK/Utf8View.h>
  31. #include <Kernel/Syscall.h>
  32. #include <alloca.h>
  33. #include <assert.h>
  34. #include <ctype.h>
  35. #include <errno.h>
  36. #include <signal.h>
  37. #include <stdio.h>
  38. #include <stdlib.h>
  39. #include <string.h>
  40. #include <sys/mman.h>
  41. #include <sys/stat.h>
  42. #include <sys/wait.h>
  43. #include <unistd.h>
  44. template<typename T, T min_value, T max_value>
  45. static inline T strtol_impl(const char* nptr, char** endptr, int base)
  46. {
  47. errno = 0;
  48. if (base < 0 || base == 1 || base > 36) {
  49. errno = EINVAL;
  50. if (endptr)
  51. *endptr = const_cast<char*>(nptr);
  52. return 0;
  53. }
  54. const char* p = nptr;
  55. while (isspace(*p))
  56. ++p;
  57. bool is_negative = false;
  58. if (*p == '-') {
  59. is_negative = true;
  60. ++p;
  61. } else {
  62. if (*p == '+')
  63. ++p;
  64. }
  65. if (base == 0 || base == 16) {
  66. if (base == 0)
  67. base = 10;
  68. if (*p == '0') {
  69. if (*(p + 1) == 'X' || *(p + 1) == 'x') {
  70. p += 2;
  71. base = 16;
  72. } else if (base != 16) {
  73. base = 8;
  74. }
  75. }
  76. }
  77. T cutoff_point = is_negative ? (min_value / base) : (max_value / base);
  78. int max_valid_digit_at_cutoff_point = is_negative ? (min_value % base) : (max_value % base);
  79. T num = 0;
  80. bool has_overflowed = false;
  81. unsigned digits_consumed = 0;
  82. for (;;) {
  83. char ch = *(p++);
  84. int digit;
  85. if (isdigit(ch))
  86. digit = ch - '0';
  87. else if (islower(ch))
  88. digit = ch - ('a' - 10);
  89. else if (isupper(ch))
  90. digit = ch - ('A' - 10);
  91. else
  92. break;
  93. if (digit >= base)
  94. break;
  95. if (has_overflowed)
  96. continue;
  97. bool is_past_cutoff = is_negative ? num < cutoff_point : num > cutoff_point;
  98. if (is_past_cutoff || (num == cutoff_point && digit > max_valid_digit_at_cutoff_point)) {
  99. has_overflowed = true;
  100. num = is_negative ? min_value : max_value;
  101. errno = ERANGE;
  102. } else {
  103. num *= base;
  104. num += is_negative ? -digit : digit;
  105. ++digits_consumed;
  106. }
  107. }
  108. if (endptr) {
  109. if (has_overflowed || digits_consumed > 0)
  110. *endptr = const_cast<char*>(p - 1);
  111. else
  112. *endptr = const_cast<char*>(nptr);
  113. }
  114. return num;
  115. }
  116. __attribute__((warn_unused_result)) int __generate_unique_filename(char* pattern)
  117. {
  118. size_t length = strlen(pattern);
  119. if (length < 6 || memcmp(pattern + length - 6, "XXXXXX", 6)) {
  120. errno = EINVAL;
  121. return -1;
  122. }
  123. size_t start = length - 6;
  124. static constexpr char random_characters[] = "abcdefghijklmnopqrstuvwxyz0123456789";
  125. for (int attempt = 0; attempt < 100; ++attempt) {
  126. for (int i = 0; i < 6; ++i)
  127. pattern[start + i] = random_characters[(rand() % sizeof(random_characters))];
  128. struct stat st;
  129. int rc = lstat(pattern, &st);
  130. if (rc < 0 && errno == ENOENT)
  131. return 0;
  132. }
  133. errno = EEXIST;
  134. return -1;
  135. }
  136. extern "C" {
  137. // Itanium C++ ABI methods defined in crt0.cpp
  138. extern int __cxa_atexit(void (*function)(void*), void* paramter, void* dso_handle);
  139. extern void __cxa_finalize(void* dso_handle);
  140. void exit(int status)
  141. {
  142. __cxa_finalize(nullptr);
  143. extern void _fini();
  144. _fini();
  145. fflush(stdout);
  146. fflush(stderr);
  147. _exit(status);
  148. ASSERT_NOT_REACHED();
  149. }
  150. static void __atexit_to_cxa_atexit(void* handler)
  151. {
  152. reinterpret_cast<void (*)()>(handler)();
  153. }
  154. int atexit(void (*handler)())
  155. {
  156. return __cxa_atexit(__atexit_to_cxa_atexit, (void*)handler, nullptr);
  157. }
  158. void abort()
  159. {
  160. raise(SIGABRT);
  161. ASSERT_NOT_REACHED();
  162. }
  163. static HashTable<const char*> s_malloced_environment_variables;
  164. static void free_environment_variable_if_needed(const char* var)
  165. {
  166. if (!s_malloced_environment_variables.contains(var))
  167. return;
  168. free(const_cast<char*>(var));
  169. s_malloced_environment_variables.remove(var);
  170. }
  171. char* getenv(const char* name)
  172. {
  173. size_t vl = strlen(name);
  174. for (size_t i = 0; environ[i]; ++i) {
  175. const char* decl = environ[i];
  176. char* eq = strchr(decl, '=');
  177. if (!eq)
  178. continue;
  179. size_t varLength = eq - decl;
  180. if (vl != varLength)
  181. continue;
  182. if (strncmp(decl, name, varLength) == 0) {
  183. return eq + 1;
  184. }
  185. }
  186. return nullptr;
  187. }
  188. int unsetenv(const char* name)
  189. {
  190. auto new_var_len = strlen(name);
  191. size_t environ_size = 0;
  192. int skip = -1;
  193. for (; environ[environ_size]; ++environ_size) {
  194. char* old_var = environ[environ_size];
  195. char* old_eq = strchr(old_var, '=');
  196. ASSERT(old_eq);
  197. size_t old_var_len = old_eq - old_var;
  198. if (new_var_len != old_var_len)
  199. continue; // can't match
  200. if (strncmp(name, old_var, new_var_len) == 0)
  201. skip = environ_size;
  202. }
  203. if (skip == -1)
  204. return 0; // not found: no failure.
  205. // Shuffle the existing array down by one.
  206. memmove(&environ[skip], &environ[skip + 1], ((environ_size - 1) - skip) * sizeof(environ[0]));
  207. environ[environ_size - 1] = nullptr;
  208. free_environment_variable_if_needed(name);
  209. return 0;
  210. }
  211. int setenv(const char* name, const char* value, int overwrite)
  212. {
  213. if (!overwrite && !getenv(name))
  214. return 0;
  215. auto length = strlen(name) + strlen(value) + 2;
  216. auto* var = (char*)malloc(length);
  217. snprintf(var, length, "%s=%s", name, value);
  218. s_malloced_environment_variables.set(var);
  219. return putenv(var);
  220. }
  221. int putenv(char* new_var)
  222. {
  223. char* new_eq = strchr(new_var, '=');
  224. if (!new_eq)
  225. return unsetenv(new_var);
  226. auto new_var_len = new_eq - new_var;
  227. int environ_size = 0;
  228. for (; environ[environ_size]; ++environ_size) {
  229. char* old_var = environ[environ_size];
  230. char* old_eq = strchr(old_var, '=');
  231. ASSERT(old_eq);
  232. auto old_var_len = old_eq - old_var;
  233. if (new_var_len != old_var_len)
  234. continue; // can't match
  235. if (strncmp(new_var, old_var, new_var_len) == 0) {
  236. free_environment_variable_if_needed(old_var);
  237. environ[environ_size] = new_var;
  238. return 0;
  239. }
  240. }
  241. // At this point, we need to append the new var.
  242. // 2 here: one for the new var, one for the sentinel value.
  243. char** new_environ = (char**)malloc((environ_size + 2) * sizeof(char*));
  244. if (new_environ == nullptr) {
  245. errno = ENOMEM;
  246. return -1;
  247. }
  248. for (int i = 0; environ[i]; ++i) {
  249. new_environ[i] = environ[i];
  250. }
  251. new_environ[environ_size] = new_var;
  252. new_environ[environ_size + 1] = nullptr;
  253. // swap new and old
  254. // note that the initial environ is not heap allocated!
  255. extern bool __environ_is_malloced;
  256. if (__environ_is_malloced)
  257. free(environ);
  258. __environ_is_malloced = true;
  259. environ = new_environ;
  260. return 0;
  261. }
  262. double strtod(const char* str, char** endptr)
  263. {
  264. size_t len = strlen(str);
  265. size_t weight = 1;
  266. int exp_val = 0;
  267. double value = 0.0f;
  268. double fraction = 0.0f;
  269. bool has_sign = false;
  270. bool is_negative = false;
  271. bool is_fractional = false;
  272. bool is_scientific = false;
  273. if (str[0] == '-') {
  274. is_negative = true;
  275. has_sign = true;
  276. }
  277. if (str[0] == '+') {
  278. has_sign = true;
  279. }
  280. size_t i;
  281. for (i = has_sign; i < len; i++) {
  282. // Looks like we're about to start working on the fractional part
  283. if (str[i] == '.') {
  284. is_fractional = true;
  285. continue;
  286. }
  287. if (str[i] == 'e' || str[i] == 'E') {
  288. if (str[i + 1] == '-')
  289. exp_val = -atoi(str + i + 2);
  290. else if (str[i + 1] == '+')
  291. exp_val = atoi(str + i + 2);
  292. else
  293. exp_val = atoi(str + i + 1);
  294. is_scientific = true;
  295. continue;
  296. }
  297. if (str[i] < '0' || str[i] > '9' || exp_val != 0)
  298. continue;
  299. if (is_fractional) {
  300. fraction *= 10;
  301. fraction += str[i] - '0';
  302. weight *= 10;
  303. } else {
  304. value = value * 10;
  305. value += str[i] - '0';
  306. }
  307. }
  308. fraction /= weight;
  309. value += fraction;
  310. if (is_scientific) {
  311. bool divide = exp_val < 0;
  312. if (divide)
  313. exp_val *= -1;
  314. for (int i = 0; i < exp_val; i++) {
  315. if (divide)
  316. value /= 10;
  317. else
  318. value *= 10;
  319. }
  320. }
  321. //FIXME: Not entirely sure if this is correct, but seems to work.
  322. if (endptr)
  323. *endptr = const_cast<char*>(str + i);
  324. return is_negative ? -value : value;
  325. }
  326. long double strtold(const char* str, char** endptr)
  327. {
  328. (void)str;
  329. (void)endptr;
  330. dbgprintf("LibC: strtold: '%s'\n", str);
  331. ASSERT_NOT_REACHED();
  332. }
  333. float strtof(const char* str, char** endptr)
  334. {
  335. (void)str;
  336. (void)endptr;
  337. dbgprintf("LibC: strtof: '%s'\n", str);
  338. ASSERT_NOT_REACHED();
  339. }
  340. double atof(const char* str)
  341. {
  342. size_t len = strlen(str);
  343. size_t weight = 1;
  344. int exp_val = 0;
  345. double value = 0.0f;
  346. double fraction = 0.0f;
  347. bool has_sign = false;
  348. bool is_negative = false;
  349. bool is_fractional = false;
  350. bool is_scientific = false;
  351. if (str[0] == '-') {
  352. is_negative = true;
  353. has_sign = true;
  354. }
  355. if (str[0] == '+') {
  356. has_sign = true;
  357. }
  358. for (size_t i = has_sign; i < len; i++) {
  359. // Looks like we're about to start working on the fractional part
  360. if (str[i] == '.') {
  361. is_fractional = true;
  362. continue;
  363. }
  364. if (str[i] == 'e' || str[i] == 'E') {
  365. if (str[i + 1] == '-' || str[i + 1] == '+')
  366. exp_val = atoi(str + i + 2);
  367. else
  368. exp_val = atoi(str + i + 1);
  369. is_scientific = true;
  370. continue;
  371. }
  372. if (str[i] < '0' || str[i] > '9' || exp_val != 0)
  373. continue;
  374. if (is_fractional) {
  375. fraction *= 10;
  376. fraction += str[i] - '0';
  377. weight *= 10;
  378. } else {
  379. value = value * 10;
  380. value += str[i] - '0';
  381. }
  382. }
  383. fraction /= weight;
  384. value += fraction;
  385. if (is_scientific) {
  386. bool divide = exp_val < 0;
  387. if (divide)
  388. exp_val *= -1;
  389. for (int i = 0; i < exp_val; i++) {
  390. if (divide)
  391. value /= 10;
  392. else
  393. value *= 10;
  394. }
  395. }
  396. return is_negative ? -value : value;
  397. }
  398. int atoi(const char* str)
  399. {
  400. size_t len = strlen(str);
  401. int value = 0;
  402. bool isNegative = false;
  403. for (size_t i = 0; i < len; ++i) {
  404. if (i == 0 && str[0] == '-') {
  405. isNegative = true;
  406. continue;
  407. }
  408. if (str[i] < '0' || str[i] > '9')
  409. return value;
  410. value = value * 10;
  411. value += str[i] - '0';
  412. }
  413. return isNegative ? -value : value;
  414. }
  415. long atol(const char* str)
  416. {
  417. static_assert(sizeof(int) == sizeof(long));
  418. return atoi(str);
  419. }
  420. long long atoll(const char* str)
  421. {
  422. dbgprintf("FIXME(Libc): atoll('%s') passing through to atol()\n", str);
  423. return atol(str);
  424. }
  425. static char ptsname_buf[32];
  426. char* ptsname(int fd)
  427. {
  428. if (ptsname_r(fd, ptsname_buf, sizeof(ptsname_buf)) < 0)
  429. return nullptr;
  430. return ptsname_buf;
  431. }
  432. int ptsname_r(int fd, char* buffer, size_t size)
  433. {
  434. int rc = syscall(SC_ptsname_r, fd, buffer, size);
  435. __RETURN_WITH_ERRNO(rc, rc, -1);
  436. }
  437. static unsigned long s_next_rand = 1;
  438. int rand()
  439. {
  440. s_next_rand = s_next_rand * 1103515245 + 12345;
  441. return ((unsigned)(s_next_rand / ((RAND_MAX + 1) * 2)) % (RAND_MAX + 1));
  442. }
  443. void srand(unsigned seed)
  444. {
  445. s_next_rand = seed;
  446. }
  447. int abs(int i)
  448. {
  449. return i < 0 ? -i : i;
  450. }
  451. long int random()
  452. {
  453. return rand();
  454. }
  455. void srandom(unsigned seed)
  456. {
  457. srand(seed);
  458. }
  459. int system(const char* command)
  460. {
  461. if (!command)
  462. return 1;
  463. auto child = fork();
  464. if (child < 0)
  465. return -1;
  466. if (!child) {
  467. int rc = execl("/bin/sh", "sh", "-c", command, nullptr);
  468. ASSERT(rc < 0);
  469. perror("execl");
  470. exit(127);
  471. }
  472. int wstatus;
  473. waitpid(child, &wstatus, 0);
  474. return WEXITSTATUS(wstatus);
  475. }
  476. char* mktemp(char* pattern)
  477. {
  478. if (__generate_unique_filename(pattern) < 0)
  479. pattern[0] = '\0';
  480. return pattern;
  481. }
  482. int mkstemp(char* pattern)
  483. {
  484. char* path = mktemp(pattern);
  485. int fd = open(path, O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR); // I'm using the flags I saw glibc using.
  486. if (fd >= 0)
  487. return fd;
  488. return -1;
  489. }
  490. char* mkdtemp(char* pattern)
  491. {
  492. if (__generate_unique_filename(pattern) < 0)
  493. return nullptr;
  494. if (mkdir(pattern, 0700) < 0)
  495. return nullptr;
  496. return pattern;
  497. }
  498. void* bsearch(const void* key, const void* base, size_t nmemb, size_t size, int (*compar)(const void*, const void*))
  499. {
  500. int low = 0;
  501. int high = nmemb - 1;
  502. while (low <= high) {
  503. int middle = (low + high) / 2;
  504. void* middle_memb = const_cast<char*>((const char*)base + middle * size);
  505. int comparison = compar(key, middle_memb);
  506. if (comparison < 0)
  507. high = middle - 1;
  508. else if (comparison > 0)
  509. low = middle + 1;
  510. else
  511. return middle_memb;
  512. }
  513. return NULL;
  514. }
  515. div_t div(int numerator, int denominator)
  516. {
  517. div_t result;
  518. result.quot = numerator / denominator;
  519. result.rem = numerator % denominator;
  520. if (numerator >= 0 && result.rem < 0) {
  521. result.quot++;
  522. result.rem -= denominator;
  523. }
  524. return result;
  525. }
  526. ldiv_t ldiv(long numerator, long denominator)
  527. {
  528. ldiv_t result;
  529. result.quot = numerator / denominator;
  530. result.rem = numerator % denominator;
  531. if (numerator >= 0 && result.rem < 0) {
  532. result.quot++;
  533. result.rem -= denominator;
  534. }
  535. return result;
  536. }
  537. size_t mbstowcs(wchar_t*, const char*, size_t)
  538. {
  539. ASSERT_NOT_REACHED();
  540. }
  541. size_t mbtowc(wchar_t* wch, const char* data, size_t data_size)
  542. {
  543. // FIXME: This needs a real implementation.
  544. UNUSED_PARAM(data_size);
  545. if (wch && data) {
  546. *wch = *data;
  547. return 1;
  548. }
  549. if (!wch && data) {
  550. return 1;
  551. }
  552. return 0;
  553. }
  554. int wctomb(char*, wchar_t)
  555. {
  556. ASSERT_NOT_REACHED();
  557. }
  558. size_t wcstombs(char* dest, const wchar_t* src, size_t max)
  559. {
  560. char* originalDest = dest;
  561. while ((size_t)(dest - originalDest) < max) {
  562. StringView v { (const char*)src, sizeof(wchar_t) };
  563. // FIXME: dependent on locale, for now utf-8 is supported.
  564. Utf8View utf8 { v };
  565. if (*utf8.begin() == '\0') {
  566. *dest = '\0';
  567. return (size_t)(dest - originalDest); // Exclude null character in returned size
  568. }
  569. for (auto byte : utf8) {
  570. if (byte != '\0')
  571. *dest++ = byte;
  572. }
  573. ++src;
  574. }
  575. return max;
  576. }
  577. long strtol(const char* str, char** endptr, int base)
  578. {
  579. return strtol_impl<long, LONG_MIN, LONG_MAX>(str, endptr, base);
  580. }
  581. unsigned long strtoul(const char* str, char** endptr, int base)
  582. {
  583. auto value = strtol(str, endptr, base);
  584. ASSERT(value >= 0);
  585. return value;
  586. }
  587. long long strtoll(const char* str, char** endptr, int base)
  588. {
  589. return strtol_impl<long long, LONG_LONG_MIN, LONG_LONG_MAX>(str, endptr, base);
  590. }
  591. unsigned long long strtoull(const char* str, char** endptr, int base)
  592. {
  593. auto value = strtoll(str, endptr, base);
  594. ASSERT(value >= 0);
  595. return value;
  596. }
  597. // Serenity's PRNG is not cryptographically secure. Do not rely on this for
  598. // any real crypto! These functions (for now) are for compatibility.
  599. // TODO: In the future, rand can be made determinstic and this not.
  600. uint32_t arc4random(void)
  601. {
  602. char buf[4];
  603. syscall(SC_getrandom, buf, 4, 0);
  604. return *(uint32_t*)buf;
  605. }
  606. void arc4random_buf(void* buffer, size_t buffer_size)
  607. {
  608. // arc4random_buf should never fail, but user supplied buffers could fail.
  609. // However, if the user passes a garbage buffer, that's on them.
  610. syscall(SC_getrandom, buffer, buffer_size, 0);
  611. }
  612. uint32_t arc4random_uniform(uint32_t max_bounds)
  613. {
  614. // XXX: Should actually apply special rules for uniformity; avoid what is
  615. // called "modulo bias".
  616. return arc4random() % max_bounds;
  617. }
  618. char* realpath(const char* pathname, char* buffer)
  619. {
  620. if (!pathname) {
  621. errno = EFAULT;
  622. return nullptr;
  623. }
  624. size_t size = PATH_MAX;
  625. if (buffer == nullptr)
  626. buffer = (char*)malloc(size);
  627. Syscall::SC_realpath_params params { { pathname, strlen(pathname) }, { buffer, size } };
  628. int rc = syscall(SC_realpath, &params);
  629. if (rc < 0) {
  630. errno = -rc;
  631. return nullptr;
  632. }
  633. errno = 0;
  634. return buffer;
  635. }
  636. int posix_openpt(int flags)
  637. {
  638. if (flags & ~(O_RDWR | O_NOCTTY | O_CLOEXEC)) {
  639. errno = EINVAL;
  640. return -1;
  641. }
  642. return open("/dev/ptmx", flags);
  643. }
  644. int grantpt(int fd)
  645. {
  646. (void)fd;
  647. return 0;
  648. }
  649. int unlockpt(int fd)
  650. {
  651. (void)fd;
  652. return 0;
  653. }
  654. }