* Made set_timezone() argument const - it's not supposed to mess with it.
* Renamed time.c to time.cpp. * set_timezone() now uses localtime_r() instead of localtime(), and will also no longer fail in case there was no timezone symlink before. * Cleaned up OS.h header. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31371 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
215c1a6c75
commit
7af3465eb5
@ -1,11 +1,11 @@
|
||||
/* Kernel specific structures and functions
|
||||
*
|
||||
* Copyright 2004-2006, Haiku Inc. All Rights Reserved.
|
||||
/*
|
||||
* Copyright 2004-2009, Haiku Inc. All Rights Reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _OS_H
|
||||
#define _OS_H
|
||||
|
||||
//! Kernel specific structures and functions
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
@ -17,7 +17,6 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*-------------------------------------------------------------*/
|
||||
/* System constants */
|
||||
|
||||
#define B_OS_NAME_LENGTH 32
|
||||
@ -37,7 +36,7 @@ enum {
|
||||
| B_TIMEOUT_REAL_TIME_BASE
|
||||
};
|
||||
|
||||
/*-------------------------------------------------------------*/
|
||||
|
||||
/* Types */
|
||||
|
||||
typedef int32 area_id;
|
||||
@ -47,7 +46,6 @@ typedef int32 team_id;
|
||||
typedef int32 thread_id;
|
||||
|
||||
|
||||
/*-------------------------------------------------------------*/
|
||||
/* Areas */
|
||||
|
||||
typedef struct area_info {
|
||||
@ -82,10 +80,11 @@ typedef struct area_info {
|
||||
#define B_READ_AREA 1
|
||||
#define B_WRITE_AREA 2
|
||||
|
||||
extern area_id create_area(const char *name, void **startAddress, uint32 addressSpec,
|
||||
size_t size, uint32 lock, uint32 protection);
|
||||
extern area_id clone_area(const char *name, void **destAddress, uint32 addressSpec,
|
||||
uint32 protection, area_id source);
|
||||
extern area_id create_area(const char *name, void **startAddress,
|
||||
uint32 addressSpec, size_t size, uint32 lock,
|
||||
uint32 protection);
|
||||
extern area_id clone_area(const char *name, void **destAddress,
|
||||
uint32 addressSpec, uint32 protection, area_id source);
|
||||
extern area_id find_area(const char *name);
|
||||
extern area_id area_for(void *address);
|
||||
extern status_t delete_area(area_id id);
|
||||
@ -103,7 +102,6 @@ extern status_t _get_next_area_info(team_id team, int32 *cookie,
|
||||
_get_next_area_info((team), (cookie), (areaInfo), sizeof(*(areaInfo)))
|
||||
|
||||
|
||||
/*-------------------------------------------------------------*/
|
||||
/* Ports */
|
||||
|
||||
typedef struct port_info {
|
||||
@ -117,24 +115,28 @@ typedef struct port_info {
|
||||
|
||||
extern port_id create_port(int32 capacity, const char *name);
|
||||
extern port_id find_port(const char *name);
|
||||
extern ssize_t read_port(port_id port, int32 *code, void *buffer, size_t bufferSize);
|
||||
extern ssize_t read_port_etc(port_id port, int32 *code, void *buffer, size_t bufferSize,
|
||||
uint32 flags, bigtime_t timeout);
|
||||
extern status_t write_port(port_id port, int32 code, const void *buffer, size_t bufferSize);
|
||||
extern ssize_t read_port(port_id port, int32 *code, void *buffer,
|
||||
size_t bufferSize);
|
||||
extern ssize_t read_port_etc(port_id port, int32 *code, void *buffer,
|
||||
size_t bufferSize, uint32 flags, bigtime_t timeout);
|
||||
extern status_t write_port(port_id port, int32 code, const void *buffer,
|
||||
size_t bufferSize);
|
||||
extern status_t write_port_etc(port_id port, int32 code, const void *buffer,
|
||||
size_t bufferSize, uint32 flags, bigtime_t timeout);
|
||||
extern status_t close_port(port_id port);
|
||||
extern status_t delete_port(port_id port);
|
||||
|
||||
extern ssize_t port_buffer_size(port_id port);
|
||||
extern ssize_t port_buffer_size_etc(port_id port, uint32 flags, bigtime_t timeout);
|
||||
extern ssize_t port_buffer_size_etc(port_id port, uint32 flags,
|
||||
bigtime_t timeout);
|
||||
extern ssize_t port_count(port_id port);
|
||||
extern status_t set_port_owner(port_id port, team_id team);
|
||||
|
||||
/* system private, use the macros instead */
|
||||
extern status_t _get_port_info(port_id port, port_info *portInfo, size_t portInfoSize);
|
||||
extern status_t _get_next_port_info(team_id team, int32 *cookie, port_info *portInfo,
|
||||
extern status_t _get_port_info(port_id port, port_info *portInfo,
|
||||
size_t portInfoSize);
|
||||
extern status_t _get_next_port_info(team_id team, int32 *cookie,
|
||||
port_info *portInfo, size_t portInfoSize);
|
||||
|
||||
#define get_port_info(port, info) \
|
||||
_get_port_info((port), (info), sizeof(*(info)))
|
||||
@ -158,10 +160,9 @@ extern status_t _get_port_message_info_etc(port_id port,
|
||||
bigtime_t timeout);
|
||||
|
||||
#define get_port_message_info_etc(port, info, flags, timeout) \
|
||||
_get_port_message_info_etc((port), (info), sizeof(*(info)), flags, \
|
||||
timeout)
|
||||
_get_port_message_info_etc((port), (info), sizeof(*(info)), flags, timeout)
|
||||
|
||||
|
||||
/*-------------------------------------------------------------*/
|
||||
/* Semaphores */
|
||||
|
||||
typedef struct sem_info {
|
||||
@ -194,21 +195,23 @@ enum {
|
||||
extern sem_id create_sem(int32 count, const char *name);
|
||||
extern status_t delete_sem(sem_id id);
|
||||
extern status_t acquire_sem(sem_id id);
|
||||
extern status_t acquire_sem_etc(sem_id id, int32 count, uint32 flags, bigtime_t timeout);
|
||||
extern status_t acquire_sem_etc(sem_id id, int32 count, uint32 flags,
|
||||
bigtime_t timeout);
|
||||
extern status_t release_sem(sem_id id);
|
||||
extern status_t release_sem_etc(sem_id id, int32 count, uint32 flags);
|
||||
/* ToDo: the following two calls are not part of the BeOS API, and might be
|
||||
/* TODO: the following two calls are not part of the BeOS API, and might be
|
||||
changed or even removed for the final release of Haiku R1 */
|
||||
extern status_t switch_sem(sem_id semToBeReleased, sem_id id);
|
||||
extern status_t switch_sem_etc(sem_id semToBeReleased, sem_id id, int32 count,
|
||||
uint32 flags, bigtime_t timeout);
|
||||
extern status_t switch_sem_etc(sem_id semToBeReleased, sem_id id,
|
||||
int32 count, uint32 flags, bigtime_t timeout);
|
||||
extern status_t get_sem_count(sem_id id, int32 *threadCount);
|
||||
extern status_t set_sem_owner(sem_id id, team_id team);
|
||||
|
||||
/* system private, use the macros instead */
|
||||
extern status_t _get_sem_info(sem_id id, struct sem_info *info, size_t infoSize);
|
||||
extern status_t _get_next_sem_info(team_id team, int32 *cookie, struct sem_info *info,
|
||||
extern status_t _get_sem_info(sem_id id, struct sem_info *info,
|
||||
size_t infoSize);
|
||||
extern status_t _get_next_sem_info(team_id team, int32 *cookie,
|
||||
struct sem_info *info, size_t infoSize);
|
||||
|
||||
#define get_sem_info(sem, info) \
|
||||
_get_sem_info((sem), (info), sizeof(*(info)))
|
||||
@ -217,7 +220,6 @@ extern status_t _get_next_sem_info(team_id team, int32 *cookie, struct sem_info
|
||||
_get_next_sem_info((team), (cookie), (info), sizeof(*(info)))
|
||||
|
||||
|
||||
/*-------------------------------------------------------------*/
|
||||
/* Teams */
|
||||
|
||||
typedef struct {
|
||||
@ -241,7 +243,8 @@ extern status_t kill_team(team_id team);
|
||||
|
||||
/* system private, use macros instead */
|
||||
extern status_t _get_team_info(team_id id, team_info *info, size_t size);
|
||||
extern status_t _get_next_team_info(int32 *cookie, team_info *info, size_t size);
|
||||
extern status_t _get_next_team_info(int32 *cookie, team_info *info,
|
||||
size_t size);
|
||||
|
||||
#define get_team_info(id, info) \
|
||||
_get_team_info((id), (info), sizeof(*(info)))
|
||||
@ -263,12 +266,13 @@ enum {
|
||||
};
|
||||
|
||||
/* system private, use macros instead */
|
||||
extern status_t _get_team_usage_info(team_id team, int32 who, team_usage_info *info, size_t size);
|
||||
extern status_t _get_team_usage_info(team_id team, int32 who,
|
||||
team_usage_info *info, size_t size);
|
||||
|
||||
#define get_team_usage_info(team, who, info) \
|
||||
_get_team_usage_info((team), (who), (info), sizeof(*(info)))
|
||||
|
||||
/*-------------------------------------------------------------*/
|
||||
|
||||
/* Threads */
|
||||
|
||||
typedef enum {
|
||||
@ -311,7 +315,8 @@ typedef status_t (*thread_func)(void *);
|
||||
#define thread_entry thread_func
|
||||
/* thread_entry is for backward compatibility only! Use thread_func */
|
||||
|
||||
extern thread_id spawn_thread(thread_func, const char *name, int32 priority, void *data);
|
||||
extern thread_id spawn_thread(thread_func, const char *name, int32 priority,
|
||||
void *data);
|
||||
extern status_t kill_thread(thread_id thread);
|
||||
extern status_t resume_thread(thread_id thread);
|
||||
extern status_t suspend_thread(thread_id thread);
|
||||
@ -319,14 +324,16 @@ extern status_t suspend_thread(thread_id thread);
|
||||
extern status_t rename_thread(thread_id thread, const char *newName);
|
||||
extern status_t set_thread_priority (thread_id thread, int32 newPriority);
|
||||
extern void exit_thread(status_t status);
|
||||
extern status_t wait_for_thread (thread_id thread, status_t *threadReturnValue);
|
||||
extern status_t wait_for_thread (thread_id thread,
|
||||
status_t *threadReturnValue);
|
||||
extern status_t on_exit_thread(void (*callback)(void *), void *data);
|
||||
|
||||
extern thread_id find_thread(const char *name);
|
||||
|
||||
extern status_t send_data(thread_id thread, int32 code, const void *buffer,
|
||||
size_t bufferSize);
|
||||
extern int32 receive_data(thread_id *sender, void *buffer, size_t bufferSize);
|
||||
extern int32 receive_data(thread_id *sender, void *buffer,
|
||||
size_t bufferSize);
|
||||
extern bool has_data(thread_id thread);
|
||||
|
||||
extern status_t snooze(bigtime_t amount);
|
||||
@ -345,17 +352,16 @@ extern status_t _get_next_thread_info(team_id team, int32 *cookie,
|
||||
_get_next_thread_info((team), (cookie), (info), sizeof(*(info)))
|
||||
|
||||
|
||||
/*-------------------------------------------------------------*/
|
||||
/* Time */
|
||||
|
||||
extern uint32 real_time_clock(void);
|
||||
extern void set_real_time_clock(uint32 secs_since_jan1_1970);
|
||||
extern void set_real_time_clock(uint32 secsSinceJan1st1970);
|
||||
extern bigtime_t real_time_clock_usecs(void);
|
||||
extern status_t set_timezone(char *timezone);
|
||||
extern bigtime_t system_time(void); /* time since booting in microseconds */
|
||||
extern status_t set_timezone(const char *timezone);
|
||||
extern bigtime_t system_time(void);
|
||||
/* time since booting in microseconds */
|
||||
|
||||
|
||||
/*-------------------------------------------------------------*/
|
||||
/* Alarm */
|
||||
|
||||
enum {
|
||||
@ -367,7 +373,6 @@ enum {
|
||||
extern bigtime_t set_alarm(bigtime_t when, uint32 flags);
|
||||
|
||||
|
||||
/*-------------------------------------------------------------*/
|
||||
/* Debugger */
|
||||
|
||||
extern void debugger(const char *message);
|
||||
@ -391,7 +396,6 @@ extern void ktrace_printf(const char *format, ...)
|
||||
extern void ktrace_vprintf(const char *format, va_list args);
|
||||
|
||||
|
||||
/*-------------------------------------------------------------*/
|
||||
/* System information */
|
||||
|
||||
#if __INTEL__
|
||||
@ -409,10 +413,8 @@ extern void ktrace_vprintf(const char *format, va_list args);
|
||||
# define B_MAX_CPU_COUNT 1
|
||||
#endif
|
||||
|
||||
#define OBOS_CPU_TYPES
|
||||
|
||||
typedef enum cpu_types {
|
||||
/* ToDo: add latest models */
|
||||
/* TODO: add latest models */
|
||||
|
||||
/* Motorola/IBM */
|
||||
B_CPU_PPC_UNKNOWN = 0,
|
||||
@ -641,7 +643,8 @@ typedef union {
|
||||
} regs;
|
||||
} cpuid_info;
|
||||
|
||||
extern status_t get_cpuid(cpuid_info *info, uint32 eaxRegister, uint32 cpuNum);
|
||||
extern status_t get_cpuid(cpuid_info *info, uint32 eaxRegister,
|
||||
uint32 cpuNum);
|
||||
#endif
|
||||
|
||||
|
||||
@ -695,17 +698,17 @@ typedef struct {
|
||||
int32 max_teams;
|
||||
int32 used_teams;
|
||||
|
||||
char kernel_name[B_FILE_NAME_LENGTH]; /* name of kernel */
|
||||
char kernel_build_date[B_OS_NAME_LENGTH]; /* date kernel built */
|
||||
char kernel_build_time[B_OS_NAME_LENGTH]; /* time kernel built */
|
||||
int64 kernel_version; /* version of this kernel */
|
||||
char kernel_name[B_FILE_NAME_LENGTH];
|
||||
char kernel_build_date[B_OS_NAME_LENGTH];
|
||||
char kernel_build_time[B_OS_NAME_LENGTH];
|
||||
int64 kernel_version;
|
||||
|
||||
bigtime_t _busy_wait_time; /* reserved for whatever */
|
||||
int32 cached_pages;
|
||||
|
||||
uint32 abi; /* the system API */
|
||||
|
||||
int32 pad[2]; /* just in case... */
|
||||
int32 pad[2];
|
||||
} system_info;
|
||||
|
||||
/* system private, use macro instead */
|
||||
|
@ -24,7 +24,7 @@ MergeObject os_main.o :
|
||||
system_info.c
|
||||
team.c
|
||||
thread.c
|
||||
time.c
|
||||
time.cpp
|
||||
syscalls.S
|
||||
wait_for_objects.cpp
|
||||
|
||||
|
@ -1,23 +1,24 @@
|
||||
/*
|
||||
* Copyright 2002-2006, Axel Dörfler, axeld@pinc-software.de.
|
||||
* Copyright 2002-2009, Axel Dörfler, axeld@pinc-software.de.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <syslog.h>
|
||||
|
||||
#include <FindDirectory.h>
|
||||
#include <OS.h>
|
||||
|
||||
#include <commpage_defs.h>
|
||||
#include <libroot_private.h>
|
||||
#include <real_time_data.h>
|
||||
#include <syscalls.h>
|
||||
|
||||
#include <FindDirectory.h>
|
||||
#include <OS.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <syslog.h>
|
||||
|
||||
|
||||
static struct real_time_data *sRealTimeData;
|
||||
static struct real_time_data* sRealTimeData;
|
||||
|
||||
|
||||
void
|
||||
@ -30,6 +31,9 @@ __init_time(void)
|
||||
}
|
||||
|
||||
|
||||
// #pragma mark - public API
|
||||
|
||||
|
||||
uint32
|
||||
real_time_clock(void)
|
||||
{
|
||||
@ -53,43 +57,40 @@ set_real_time_clock(uint32 secs)
|
||||
|
||||
|
||||
status_t
|
||||
set_timezone(char *timezone)
|
||||
set_timezone(const char* timezone)
|
||||
{
|
||||
char path[B_PATH_NAME_LENGTH];
|
||||
char tzfilename[B_PATH_NAME_LENGTH];
|
||||
status_t status = find_directory(B_USER_SETTINGS_DIRECTORY, -1, true, path,
|
||||
B_PATH_NAME_LENGTH);
|
||||
if (status != B_OK) {
|
||||
syslog(LOG_ERR, "can't find settings directory: %s\n", strerror(status));
|
||||
return status;
|
||||
}
|
||||
|
||||
strlcat(path, "/timezone", sizeof(path));
|
||||
|
||||
if (unlink(path) != 0 && errno != ENOENT) {
|
||||
syslog(LOG_ERR, "can't unlink: %s\n", strerror(errno));
|
||||
return errno;
|
||||
}
|
||||
|
||||
if (symlink(timezone, path) != 0) {
|
||||
syslog(LOG_ERR, "can't symlink: %s\n", strerror(errno));
|
||||
return errno;
|
||||
}
|
||||
|
||||
bool isGMT;
|
||||
|
||||
status_t err;
|
||||
struct tm *tm;
|
||||
time_t t;
|
||||
|
||||
if ((err = find_directory(B_USER_SETTINGS_DIRECTORY, -1, true, path, B_PATH_NAME_LENGTH)) != B_OK) {
|
||||
fprintf(stderr, "can't find settings directory: %s\n", strerror(err));
|
||||
return err;
|
||||
}
|
||||
strcat(path, "/timezone");
|
||||
|
||||
err = unlink(path);
|
||||
if (err != B_OK) {
|
||||
fprintf(stderr, "can't unlink: %s\n", strerror(err));
|
||||
return err;
|
||||
}
|
||||
err = symlink(timezone, path);
|
||||
if (err != B_OK) {
|
||||
fprintf(stderr, "can't symlink: %s\n", strerror(err));
|
||||
return err;
|
||||
}
|
||||
_kern_get_tzfilename(tzfilename, sizeof(tzfilename), &isGMT);
|
||||
_kern_get_tzfilename(NULL, 0, &isGMT);
|
||||
_kern_set_tzfilename(timezone, strlen(timezone), isGMT);
|
||||
|
||||
tzset();
|
||||
|
||||
time(&t);
|
||||
tm = localtime(&t);
|
||||
time_t seconds;
|
||||
time(&seconds);
|
||||
struct tm tm;
|
||||
localtime_r(&seconds, &tm);
|
||||
|
||||
if ((err = _kern_set_timezone(tm->tm_gmtoff, tm->tm_isdst)) < B_OK)
|
||||
return err;
|
||||
|
||||
return B_OK;
|
||||
return _kern_set_timezone(tm.tm_gmtoff, tm.tm_isdst);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user