source: mainline/uspace/lib/posix/include/posix/time.h@ fdf97f6

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since fdf97f6 was fdf97f6, checked in by Vojtech Horky <vojtechhorky@…>, 13 years ago

Libposix functions are without posix_ prefix

Prior this commit, libposix headers declared all functions as posix_*
and used macros to rename e.g. strncpy to posix_strncpy in all (ported)
sources.

After this change, libposix headers look as normal POSIX compliant headers
(well, almost) and no renaming is done in the source codei (of the ported
applications). Instead, the renaming is done at object files level to
bypass weird problems that are bound to happen if you use macros.

The scheme is following. libposix headers use special macro to declare
the names. When included from outside, the functions have their normal
(standard) names. When included from the libposix sources, posix_ prefix
is added. Thus, when libposix is compiled and linked, it contains the
posix_* naming while compiling of ported software uses the normal
non-prefixed versions. This way the posix_* can use HelenOS libc without
any problem. Before linking, the posix_* prefix is removed from all
symbols and special prefix helenos_libc_ is added to all functions
that exists in our (HelenOS) libc and its name clashes with the POSIX
one.

The following happens, for example, to the open() function that exists in
both libposix and in libc.

  • Headers and sources of libc are left intact.
  • Copy of libc.a is made and to all clashing functions is added the helenos_libc prefix. This library is called libc4posix.a.
  • POSIX_DEF(open)(const char *) is used in libposix headers. This macro expands to plain open when included from the "outside world". But it expands to posix_open when included from libposix sources.
  • Libposix is compiled and linked, containing posix_open() that internally calls open() [the original one from libc].
  • Libposix is transformed - all open() are replaced with prefix variant: helenos_libc_open() and all posix_open() are replaced with open(). The transformed library is stored as libposixaslibc.a

Binutils and PCC are then linked with libc4posix and libposixaslibc
libraries instead of libc and libposix as was done previously.

WARNING: it looks that binutils, PCC and MSIM still works but not all
architectures were tested.

  • Property mode set to 100644
File size: 4.0 KB
Line 
1/*
2 * Copyright (c) 2011 Petr Koupy
3 * Copyright (c) 2011 Jiri Zarevucky
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * - Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * - Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * - The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30/** @addtogroup libposix
31 * @{
32 */
33/** @file Time measurement support.
34 */
35
36#ifndef POSIX_TIME_H_
37#define POSIX_TIME_H_
38
39#ifndef __POSIX_DEF__
40#define __POSIX_DEF__(x) x
41#endif
42
43#include "sys/types.h"
44
45#ifndef NULL
46 #define NULL ((void *) 0)
47#endif
48
49#ifndef CLOCKS_PER_SEC
50 #define CLOCKS_PER_SEC (1000000L)
51#endif
52
53#ifndef __locale_t_defined
54 #define __locale_t_defined
55 typedef struct __posix_locale *__POSIX_DEF__(locale_t);
56 #ifndef LIBPOSIX_INTERNAL
57 #define locale_t __POSIX_DEF__(locale_t)
58 #endif
59#endif
60
61#ifndef POSIX_SIGNAL_H_
62 struct __POSIX_DEF__(sigevent);
63 #ifndef LIBPOSIX_INTERNAL
64 #define sigevent __POSIX_DEF__(sigevent)
65 #endif
66#endif
67
68#undef CLOCK_REALTIME
69#define CLOCK_REALTIME ((__POSIX_DEF__(clockid_t)) 0)
70
71struct __POSIX_DEF__(timespec) {
72 time_t tv_sec; /* Seconds. */
73 long tv_nsec; /* Nanoseconds. */
74};
75
76struct __POSIX_DEF__(itimerspec) {
77 struct __POSIX_DEF__(timespec) it_interval; /* Timer period. */
78 struct __POSIX_DEF__(timespec) it_value; /* Timer expiration. */
79};
80
81typedef struct __posix_timer *__POSIX_DEF__(timer_t);
82
83/* Timezones */
84extern int __POSIX_DEF__(daylight);
85extern long __POSIX_DEF__(timezone);
86extern char *__POSIX_DEF__(tzname)[2];
87extern void __POSIX_DEF__(tzset)(void);
88
89/* Broken-down Time */
90extern struct tm *__POSIX_DEF__(gmtime_r)(const time_t *restrict timer,
91 struct tm *restrict result);
92extern struct tm *__POSIX_DEF__(gmtime)(const time_t *restrict timep);
93extern struct tm *__POSIX_DEF__(localtime_r)(const time_t *restrict timer,
94 struct tm *restrict result);
95extern struct tm *__POSIX_DEF__(localtime)(const time_t *restrict timep);
96
97/* Formatting Calendar Time */
98extern char *__POSIX_DEF__(asctime_r)(const struct tm *restrict timeptr,
99 char *restrict buf);
100extern char *__POSIX_DEF__(asctime)(const struct tm *restrict timeptr);
101extern char *__POSIX_DEF__(ctime_r)(const time_t *timer, char *buf);
102extern char *__POSIX_DEF__(ctime)(const time_t *timer);
103
104/* Clocks */
105extern int __POSIX_DEF__(clock_getres)(__POSIX_DEF__(clockid_t) clock_id,
106 struct __POSIX_DEF__(timespec) *res);
107extern int __POSIX_DEF__(clock_gettime)(__POSIX_DEF__(clockid_t) clock_id,
108 struct __POSIX_DEF__(timespec) *tp);
109extern int __POSIX_DEF__(clock_settime)(__POSIX_DEF__(clockid_t) clock_id,
110 const struct __POSIX_DEF__(timespec) *tp);
111extern int __POSIX_DEF__(clock_nanosleep)(__POSIX_DEF__(clockid_t) clock_id, int flags,
112 const struct __POSIX_DEF__(timespec) *rqtp, struct __POSIX_DEF__(timespec) *rmtp);
113
114/* CPU Time */
115extern __POSIX_DEF__(clock_t) __POSIX_DEF__(clock)(void);
116
117
118#endif // POSIX_TIME_H_
119
120/** @}
121 */
Note: See TracBrowser for help on using the repository browser.