00001 /* 00002 * Copyright (c) 2000, 2001, 2002 Fabrice Bellard 00003 * Copyright (c) 2007 Mans Rullgard 00004 * 00005 * This file is part of FFmpeg. 00006 * 00007 * FFmpeg is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU Lesser General Public 00009 * License as published by the Free Software Foundation; either 00010 * version 2.1 of the License, or (at your option) any later version. 00011 * 00012 * FFmpeg is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 * Lesser General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU Lesser General Public 00018 * License along with FFmpeg; if not, write to the Free Software 00019 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00020 */ 00021 00022 #include <stdarg.h> 00023 #include <stdio.h> 00024 #include <string.h> 00025 #include <ctype.h> 00026 #include "avstring.h" 00027 00028 int av_strstart(const char *str, const char *pfx, const char **ptr) 00029 { 00030 while (*pfx && *pfx == *str) { 00031 pfx++; 00032 str++; 00033 } 00034 if (!*pfx && ptr) 00035 *ptr = str; 00036 return !*pfx; 00037 } 00038 00039 int av_stristart(const char *str, const char *pfx, const char **ptr) 00040 { 00041 while (*pfx && toupper((unsigned)*pfx) == toupper((unsigned)*str)) { 00042 pfx++; 00043 str++; 00044 } 00045 if (!*pfx && ptr) 00046 *ptr = str; 00047 return !*pfx; 00048 } 00049 00050 size_t av_strlcpy(char *dst, const char *src, size_t size) 00051 { 00052 size_t len = 0; 00053 while (++len < size && *src) 00054 *dst++ = *src++; 00055 if (len <= size) 00056 *dst = 0; 00057 return len + strlen(src) - 1; 00058 } 00059 00060 size_t av_strlcat(char *dst, const char *src, size_t size) 00061 { 00062 size_t len = strlen(dst); 00063 if (size <= len + 1) 00064 return len + strlen(src); 00065 return len + av_strlcpy(dst + len, src, size - len); 00066 } 00067 00068 size_t av_strlcatf(char *dst, size_t size, const char *fmt, ...) 00069 { 00070 int len = strlen(dst); 00071 va_list vl; 00072 00073 va_start(vl, fmt); 00074 len += vsnprintf(dst + len, size > len ? size - len : 0, fmt, vl); 00075 va_end(vl); 00076 00077 return len; 00078 }