2 * Copyright 2002-2007, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
3 * Distributed under the terms of the MIT License.
13 #include <sys/resource.h>
14 #include <sys/statvfs.h>
16 #include <SupportDefs.h>
18 #include <directories.h>
20 #include <posix/realtime_sem_defs.h>
21 #include <signal_defs.h>
22 #include <symbol_versioning.h>
24 #include <thread_defs.h>
25 #include <user_group.h>
26 #include <user_timer_defs.h>
29 #include <errno_private.h>
30 #include <libroot_private.h>
31 #include <time_private.h>
32 #include <unistd_private.h>
39 if (getrlimit(RLIMIT_NOFILE
, &rlimit
) < 0)
42 return rlimit
.rlim_cur
;
47 __sysconf_beos(int name
)
54 return __sysconf(name
);
62 // TODO: This is about what BeOS does, better POSIX conformance would be
77 return getdtablesize();
85 return _POSIX_VERSION
;
86 case _SC_GETGR_R_SIZE_MAX
:
87 return MAX_GROUP_BUFFER_SIZE
;
88 case _SC_GETPW_R_SIZE_MAX
:
89 return MAX_PASSWD_BUFFER_SIZE
;
92 case _SC_SEM_NSEMS_MAX
:
93 return _POSIX_SEM_NSEMS_MAX
;
94 case _SC_SEM_VALUE_MAX
:
95 return _POSIX_SEM_VALUE_MAX
;
97 return _POSIX_SEMAPHORES
;
99 return _POSIX_THREADS
;
102 case _SC_NPROCESSORS_CONF
:
105 err
= get_system_info(&info
);
110 return info
.cpu_count
;
112 case _SC_NPROCESSORS_ONLN
:
117 err
= get_system_info(&info
);
122 for (i
= 0; i
< info
.cpu_count
; i
++)
123 if (_kern_cpu_enabled(i
))
131 //XXX:return PASS_MAX;
135 err
= get_system_info(&info
);
140 return info
.max_pages
;
142 case _SC_AVPHYS_PAGES
:
145 err
= get_system_info(&info
);
150 return info
.max_pages
- info
.used_pages
;
152 case _SC_MAPPED_FILES
:
153 return _POSIX_MAPPED_FILES
;
154 case _SC_THREAD_PROCESS_SHARED
:
155 return _POSIX_THREAD_PROCESS_SHARED
;
156 case _SC_THREAD_STACK_MIN
:
157 return MIN_USER_STACK_SIZE
;
158 case _SC_THREAD_ATTR_STACKADDR
:
159 return _POSIX_THREAD_ATTR_STACKADDR
;
160 case _SC_THREAD_ATTR_STACKSIZE
:
161 return _POSIX_THREAD_ATTR_STACKSIZE
;
162 case _SC_THREAD_PRIORITY_SCHEDULING
:
163 return _POSIX_THREAD_PRIORITY_SCHEDULING
;
164 case _SC_REALTIME_SIGNALS
:
165 return _POSIX_REALTIME_SIGNALS
;
166 case _SC_MEMORY_PROTECTION
:
167 return _POSIX_MEMORY_PROTECTION
;
168 case _SC_SIGQUEUE_MAX
:
169 return MAX_QUEUED_SIGNALS
;
171 return SIGRTMAX
- SIGRTMIN
+ 1;
172 case _SC_MONOTONIC_CLOCK
:
173 return _POSIX_MONOTONIC_CLOCK
;
174 case _SC_DELAYTIMER_MAX
:
175 return MAX_USER_TIMER_OVERRUN_COUNT
;
177 return MAX_USER_TIMERS_PER_TEAM
;
179 return _POSIX_TIMERS
;
181 return _POSIX_CPUTIME
;
182 case _SC_THREAD_CPUTIME
:
183 return _POSIX_THREAD_CPUTIME
;
185 // not POSIX (anymore)
206 fstype(const char *fsh_name
)
208 if (!strncmp(fsh_name
, "bfs", B_OS_NAME_LENGTH
))
210 if (!strncmp(fsh_name
, "dos", B_OS_NAME_LENGTH
))
212 if (!strncmp(fsh_name
, "fat", B_OS_NAME_LENGTH
))
214 if (!strncmp(fsh_name
, "ext2", B_OS_NAME_LENGTH
))
216 if (!strncmp(fsh_name
, "ext3", B_OS_NAME_LENGTH
))
224 __pathconf_common(struct statvfs
*fs
, struct stat
*st
,
229 ret
= fs_stat_dev(fs
->f_fsid
, &info
);
235 // TODO: many cases should check for file type from st.
237 case _PC_CHOWN_RESTRICTED
:
238 return _POSIX_CHOWN_RESTRICTED
;
247 return fs
->f_namemax
;
251 return _POSIX_NO_TRUNC
;
257 return VFS_FIFO_ATOMIC_WRITE_SIZE
;
263 return _POSIX_VDISABLE
;
265 case _PC_FILESIZEBITS
:
267 int type
= fstype(info
.fsh_name
);
275 // XXX: add fs ? add to statvfs/fs_info ?
279 case _PC_SYMLINK_MAX
:
284 int type
= fstype(info
.fsh_name
);
292 // XXX: there should be an HAS_SYMLINKS flag
297 case _PC_XATTR_EXISTS
:
298 case _PC_XATTR_ENABLED
:
301 /* those seem to be Solaris specific,
302 * else we should return 1 I suppose.
303 * we don't yet map POSIX xattrs
304 * to BFS ones anyway.
306 if (info
.flags
& B_FS_HAS_ATTR
)
317 case _PC_SOCK_MAXBUF
:
318 case _PC_REC_INCR_XFER_SIZE
:
319 case _PC_REC_MAX_XFER_SIZE
:
320 case _PC_REC_MIN_XFER_SIZE
:
321 case _PC_REC_XFER_ALIGN
:
322 case _PC_ALLOC_SIZE_MIN
:
323 /* not yet supported */
335 fpathconf(int fd
, int name
)
344 ret
= fstat(fd
, &st
);
347 ret
= fstatvfs(fd
, &fs
);
350 return __pathconf_common(&fs
, &st
, name
);
355 pathconf(const char *path
, int name
)
364 ret
= lstat(path
, &st
);
367 ret
= statvfs(path
, &fs
);
370 return __pathconf_common(&fs
, &st
, name
);
375 confstr(int name
, char *buffer
, size_t length
)
377 size_t stringLength
= 0;
378 const char *string
= "";
380 if (!length
|| !buffer
) {
387 string
= kSystemNonpackagedBinDirectory
":" kGlobalBinDirectory
":"
388 kSystemAppsDirectory
":" kSystemPreferencesDirectory
;
395 if (buffer
!= NULL
) {
396 stringLength
= strlen(string
) + 1;
397 strlcpy(buffer
, string
,
398 min_c(length
- 1, stringLength
));
405 DEFINE_LIBROOT_KERNEL_SYMBOL_VERSION("__sysconf_beos", "sysconf@", "BASE");
407 DEFINE_LIBROOT_KERNEL_SYMBOL_VERSION("__sysconf", "sysconf@@", "1_ALPHA4");