* Fixed warning.

* Use strlcpy() to copy the confstr instead of strncpy().


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22565 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2007-10-15 11:57:28 +00:00
parent dcdb996481
commit c3d49e1317
+25 -19
View File
@@ -1,16 +1,21 @@
/* /*
** Copyright 2002-2004, Axel Dörfler, [email protected]. All rights reserved. * Copyright 2002-2007, Axel Dörfler, [email protected]. All rights reserved.
** Distributed under the terms of the Haiku License. * Distributed under the terms of the MIT License.
*/ */
#include <unistd.h> #include <unistd.h>
#include <sys/resource.h>
#include <stdio.h>
#include <errno.h> #include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/resource.h>
#include <SupportDefs.h>
int int
getdtablesize(void) getdtablesize(void)
{ {
struct rlimit rlimit; struct rlimit rlimit;
@@ -21,10 +26,10 @@ getdtablesize(void)
} }
long long
sysconf(int name) sysconf(int name)
{ {
// This is about what BeOS does, better POSIX conformance would be nice, though // TODO: This is about what BeOS does, better POSIX conformance would be nice, though
switch (name) { switch (name) {
case _SC_ARG_MAX: case _SC_ARG_MAX:
@@ -53,7 +58,7 @@ sysconf(int name)
} }
long long
fpathconf(int fd, int name) fpathconf(int fd, int name)
{ {
switch (name) { switch (name) {
@@ -94,20 +99,19 @@ fpathconf(int fd, int name)
} }
long long
pathconf(const char *path, int name) pathconf(const char *path, int name)
{ {
return fpathconf(-1, name); return fpathconf(-1, name);
} }
#define min_c(a,b) ((a)>(b)?(b):(a)) size_t
confstr(int name, char *buffer, size_t length)
size_t
confstr(int name, char *buf, size_t len)
{ {
size_t string_len = 1; size_t stringLength = 1;
char *string = ""; char *string = "";
switch (name) { switch (name) {
case 0: case 0:
break; break;
@@ -115,8 +119,10 @@ confstr(int name, char *buf, size_t len)
errno = EINVAL; errno = EINVAL;
return 0; return 0;
} }
if (buf != NULL)
strncpy(buf, string, min_c(len, string_len)); if (buffer != NULL)
return string_len; strlcpy(buffer, string, min_c(length, stringLength));
return stringLength;
} }