diff options
Diffstat (limited to 'APACHE_1_3_42/src/ap/ap_cpystrn.c')
-rw-r--r-- | APACHE_1_3_42/src/ap/ap_cpystrn.c | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/APACHE_1_3_42/src/ap/ap_cpystrn.c b/APACHE_1_3_42/src/ap/ap_cpystrn.c new file mode 100644 index 0000000000..4601488a11 --- /dev/null +++ b/APACHE_1_3_42/src/ap/ap_cpystrn.c @@ -0,0 +1,52 @@ +/* Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "httpd.h" + +/* + * Apache's "replacement" for the strncpy() function. We roll our + * own to implement these specific changes: + * (1) strncpy() doesn't always null terminate and we want it to. + * (2) strncpy() null fills, which is bogus, esp. when copy 8byte + * strings into 8k blocks. + * (3) Instead of returning the pointer to the beginning of + * the destination string, we return a pointer to the + * terminating '\0' to allow us to "check" for truncation + * + * ap_cpystrn() follows the same call structure as strncpy(). + */ + +API_EXPORT(char *) ap_cpystrn(char *dst, const char *src, size_t dst_size) +{ + + char *d, *end; + + if (!dst_size) + return (dst); + + d = dst; + end = dst + dst_size - 1; + + for (; d < end; ++d, ++src) { + if (!(*d = *src)) { + return (d); + } + } + + *d = '\0'; /* always null terminate */ + + return (d); +} |