[444] | 1 | /* |
---|
| 2 | Copyright (c) 2015, Synopsys, Inc. All rights reserved. |
---|
| 3 | |
---|
| 4 | Redistribution and use in source and binary forms, with or without |
---|
| 5 | modification, are permitted provided that the following conditions are met: |
---|
| 6 | |
---|
| 7 | 1) Redistributions of source code must retain the above copyright notice, |
---|
| 8 | this list of conditions and the following disclaimer. |
---|
| 9 | |
---|
| 10 | 2) Redistributions in binary form must reproduce the above copyright notice, |
---|
| 11 | this list of conditions and the following disclaimer in the documentation |
---|
| 12 | and/or other materials provided with the distribution. |
---|
| 13 | |
---|
| 14 | 3) Neither the name of the Synopsys, Inc., nor the names of its contributors |
---|
| 15 | may be used to endorse or promote products derived from this software |
---|
| 16 | without specific prior written permission. |
---|
| 17 | |
---|
| 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
| 19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
| 20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
| 21 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
---|
| 22 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
| 23 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
| 24 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
| 25 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
| 26 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
| 27 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
---|
| 28 | POSSIBILITY OF SUCH DAMAGE. |
---|
| 29 | */ |
---|
| 30 | |
---|
| 31 | /* This file has been copied from libgloss/arm/libcfuncs.c. |
---|
| 32 | |
---|
| 33 | Support files for GNU libc. Files in the C namespace go here. |
---|
| 34 | Files in the system namespace (ie those that start with an underscore) |
---|
| 35 | go in syscalls.c. |
---|
| 36 | |
---|
| 37 | Note: These functions are in a seperate file so that OS providers can |
---|
| 38 | overrride the system call stubs (defined in syscalls.c) without having |
---|
| 39 | to provide libc functions as well. */ |
---|
| 40 | |
---|
| 41 | #include <errno.h> |
---|
| 42 | #include <sys/types.h> |
---|
| 43 | #include <time.h> |
---|
| 44 | #include <unistd.h> |
---|
| 45 | |
---|
| 46 | unsigned __attribute__((weak)) |
---|
| 47 | alarm (unsigned seconds) |
---|
| 48 | { |
---|
| 49 | (void)seconds; |
---|
| 50 | return 0; |
---|
| 51 | } |
---|
| 52 | |
---|
| 53 | clock_t _clock (void); |
---|
| 54 | clock_t __attribute__((weak)) |
---|
| 55 | clock (void) |
---|
| 56 | { |
---|
| 57 | return _clock (); |
---|
| 58 | } |
---|
| 59 | |
---|
| 60 | int _isatty (int fildes); |
---|
| 61 | int __attribute__((weak)) |
---|
| 62 | isatty (int fildes) |
---|
| 63 | { |
---|
| 64 | return _isatty (fildes); |
---|
| 65 | } |
---|
| 66 | |
---|
| 67 | int __attribute__((weak)) |
---|
| 68 | pause (void) |
---|
| 69 | { |
---|
| 70 | errno = ENOSYS; |
---|
| 71 | return -1; |
---|
| 72 | } |
---|
| 73 | |
---|
| 74 | unsigned __attribute__((weak)) |
---|
| 75 | sleep (unsigned seconds) |
---|
| 76 | { |
---|
| 77 | clock_t t0 = _clock (); |
---|
| 78 | clock_t dt = seconds * CLOCKS_PER_SEC; |
---|
| 79 | |
---|
| 80 | while (_clock () - t0 < dt); |
---|
| 81 | return 0; |
---|
| 82 | } |
---|
| 83 | |
---|
| 84 | int __attribute__((weak)) |
---|
| 85 | usleep (useconds_t useconds) |
---|
| 86 | { |
---|
| 87 | clock_t t0 = _clock (); |
---|
| 88 | clock_t dt = useconds / (1000000/CLOCKS_PER_SEC); |
---|
| 89 | |
---|
| 90 | while (_clock () - t0 < dt); |
---|
| 91 | return 0; |
---|
| 92 | } |
---|