2008-04-14 23:55:36 +09:00
|
|
|
/**************************************************************************
|
|
|
|
|
*
|
s/Tungsten Graphics/VMware/
Tungsten Graphics Inc. was acquired by VMware Inc. in 2008. Leaving the
old copyright name is creating unnecessary confusion, hence this change.
This was the sed script I used:
$ cat tg2vmw.sed
# Run as:
#
# git reset --hard HEAD && find include scons src -type f -not -name 'sed*' -print0 | xargs -0 sed -i -f tg2vmw.sed
#
# Rename copyrights
s/Tungsten Gra\(ph\|hp\)ics,\? [iI]nc\.\?\(, Cedar Park\)\?\(, Austin\)\?\(, \(Texas\|TX\)\)\?\.\?/VMware, Inc./g
/Copyright/s/Tungsten Graphics\(,\? [iI]nc\.\)\?\(, Cedar Park\)\?\(, Austin\)\?\(, \(Texas\|TX\)\)\?\.\?/VMware, Inc./
s/TUNGSTEN GRAPHICS/VMWARE/g
# Rename emails
s/alanh@tungstengraphics.com/alanh@vmware.com/
s/jens@tungstengraphics.com/jowen@vmware.com/g
s/jrfonseca-at-tungstengraphics-dot-com/jfonseca-at-vmware-dot-com/
s/jrfonseca\?@tungstengraphics.com/jfonseca@vmware.com/g
s/keithw\?@tungstengraphics.com/keithw@vmware.com/g
s/michel@tungstengraphics.com/daenzer@vmware.com/g
s/thomas-at-tungstengraphics-dot-com/thellstom-at-vmware-dot-com/
s/zack@tungstengraphics.com/zackr@vmware.com/
# Remove dead links
s@Tungsten Graphics (http://www.tungstengraphics.com)@Tungsten Graphics@g
# C string src/gallium/state_trackers/vega/api_misc.c
s/"Tungsten Graphics, Inc"/"VMware, Inc"/
Reviewed-by: Brian Paul <brianp@vmware.com>
2014-01-17 16:27:50 +00:00
|
|
|
* Copyright 2008 VMware, Inc.
|
2008-04-14 23:55:36 +09:00
|
|
|
* All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
|
* copy of this software and associated documentation files (the
|
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
|
* distribute, sub license, and/or sell copies of the Software, and to
|
|
|
|
|
* permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
|
* the following conditions:
|
|
|
|
|
*
|
|
|
|
|
* The above copyright notice and this permission notice (including the
|
|
|
|
|
* next paragraph) shall be included in all copies or substantial portions
|
|
|
|
|
* of the Software.
|
|
|
|
|
*
|
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
|
s/Tungsten Graphics/VMware/
Tungsten Graphics Inc. was acquired by VMware Inc. in 2008. Leaving the
old copyright name is creating unnecessary confusion, hence this change.
This was the sed script I used:
$ cat tg2vmw.sed
# Run as:
#
# git reset --hard HEAD && find include scons src -type f -not -name 'sed*' -print0 | xargs -0 sed -i -f tg2vmw.sed
#
# Rename copyrights
s/Tungsten Gra\(ph\|hp\)ics,\? [iI]nc\.\?\(, Cedar Park\)\?\(, Austin\)\?\(, \(Texas\|TX\)\)\?\.\?/VMware, Inc./g
/Copyright/s/Tungsten Graphics\(,\? [iI]nc\.\)\?\(, Cedar Park\)\?\(, Austin\)\?\(, \(Texas\|TX\)\)\?\.\?/VMware, Inc./
s/TUNGSTEN GRAPHICS/VMWARE/g
# Rename emails
s/alanh@tungstengraphics.com/alanh@vmware.com/
s/jens@tungstengraphics.com/jowen@vmware.com/g
s/jrfonseca-at-tungstengraphics-dot-com/jfonseca-at-vmware-dot-com/
s/jrfonseca\?@tungstengraphics.com/jfonseca@vmware.com/g
s/keithw\?@tungstengraphics.com/keithw@vmware.com/g
s/michel@tungstengraphics.com/daenzer@vmware.com/g
s/thomas-at-tungstengraphics-dot-com/thellstom-at-vmware-dot-com/
s/zack@tungstengraphics.com/zackr@vmware.com/
# Remove dead links
s@Tungsten Graphics (http://www.tungstengraphics.com)@Tungsten Graphics@g
# C string src/gallium/state_trackers/vega/api_misc.c
s/"Tungsten Graphics, Inc"/"VMware, Inc"/
Reviewed-by: Brian Paul <brianp@vmware.com>
2014-01-17 16:27:50 +00:00
|
|
|
* IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
|
2008-04-14 23:55:36 +09:00
|
|
|
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
|
|
|
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
|
|
|
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
|
*
|
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @file
|
|
|
|
|
* Platform independent functions for string manipulation.
|
2008-08-07 09:12:55 +01:00
|
|
|
*
|
s/Tungsten Graphics/VMware/
Tungsten Graphics Inc. was acquired by VMware Inc. in 2008. Leaving the
old copyright name is creating unnecessary confusion, hence this change.
This was the sed script I used:
$ cat tg2vmw.sed
# Run as:
#
# git reset --hard HEAD && find include scons src -type f -not -name 'sed*' -print0 | xargs -0 sed -i -f tg2vmw.sed
#
# Rename copyrights
s/Tungsten Gra\(ph\|hp\)ics,\? [iI]nc\.\?\(, Cedar Park\)\?\(, Austin\)\?\(, \(Texas\|TX\)\)\?\.\?/VMware, Inc./g
/Copyright/s/Tungsten Graphics\(,\? [iI]nc\.\)\?\(, Cedar Park\)\?\(, Austin\)\?\(, \(Texas\|TX\)\)\?\.\?/VMware, Inc./
s/TUNGSTEN GRAPHICS/VMWARE/g
# Rename emails
s/alanh@tungstengraphics.com/alanh@vmware.com/
s/jens@tungstengraphics.com/jowen@vmware.com/g
s/jrfonseca-at-tungstengraphics-dot-com/jfonseca-at-vmware-dot-com/
s/jrfonseca\?@tungstengraphics.com/jfonseca@vmware.com/g
s/keithw\?@tungstengraphics.com/keithw@vmware.com/g
s/michel@tungstengraphics.com/daenzer@vmware.com/g
s/thomas-at-tungstengraphics-dot-com/thellstom-at-vmware-dot-com/
s/zack@tungstengraphics.com/zackr@vmware.com/
# Remove dead links
s@Tungsten Graphics (http://www.tungstengraphics.com)@Tungsten Graphics@g
# C string src/gallium/state_trackers/vega/api_misc.c
s/"Tungsten Graphics, Inc"/"VMware, Inc"/
Reviewed-by: Brian Paul <brianp@vmware.com>
2014-01-17 16:27:50 +00:00
|
|
|
* @author Jose Fonseca <jfonseca@vmware.com>
|
2008-04-14 23:55:36 +09:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef U_STRING_H_
|
|
|
|
|
#define U_STRING_H_
|
|
|
|
|
|
2015-07-22 13:21:24 +01:00
|
|
|
#if !defined(XF86_LIBC_H)
|
2008-04-14 23:55:36 +09:00
|
|
|
#include <stdio.h>
|
|
|
|
|
#endif
|
2017-10-02 16:33:46 -06:00
|
|
|
#include <stdlib.h>
|
2008-04-14 23:55:36 +09:00
|
|
|
#include <stddef.h>
|
|
|
|
|
#include <stdarg.h>
|
2017-10-03 13:56:01 -06:00
|
|
|
#include <string.h>
|
2008-04-14 23:55:36 +09:00
|
|
|
|
2015-07-22 13:21:24 +01:00
|
|
|
#include "util/macros.h" // PRINTFLIKE
|
2008-05-05 23:58:37 +09:00
|
|
|
|
2008-04-14 23:55:36 +09:00
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
|
extern "C" {
|
|
|
|
|
#endif
|
|
|
|
|
|
2018-11-20 11:24:55 +00:00
|
|
|
#ifndef _GNU_SOURCE
|
2011-11-25 14:37:07 +01:00
|
|
|
|
2018-11-20 11:24:55 +00:00
|
|
|
#define strchrnul util_strchrnul
|
2015-07-20 19:58:43 -04:00
|
|
|
static inline char *
|
2011-11-25 14:37:07 +01:00
|
|
|
util_strchrnul(const char *s, char c)
|
|
|
|
|
{
|
|
|
|
|
for (; *s && *s != c; ++s);
|
|
|
|
|
|
|
|
|
|
return (char *)s;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|
2008-08-07 09:12:55 +01:00
|
|
|
|
2015-07-22 13:21:24 +01:00
|
|
|
#ifdef _WIN32
|
2008-08-07 09:12:55 +01:00
|
|
|
|
2015-07-22 13:21:24 +01:00
|
|
|
static inline int
|
|
|
|
|
util_vsnprintf(char *str, size_t size, const char *format, va_list ap)
|
|
|
|
|
{
|
|
|
|
|
/* We need to use _vscprintf to calculate the length as vsnprintf returns -1
|
|
|
|
|
* if the number of characters to write is greater than count.
|
|
|
|
|
*/
|
|
|
|
|
va_list ap_copy;
|
|
|
|
|
int ret;
|
|
|
|
|
va_copy(ap_copy, ap);
|
|
|
|
|
ret = _vsnprintf(str, size, format, ap);
|
|
|
|
|
if (ret < 0) {
|
|
|
|
|
ret = _vscprintf(format, ap_copy);
|
|
|
|
|
}
|
2018-09-06 17:43:54 +03:00
|
|
|
va_end(ap_copy);
|
2015-07-22 13:21:24 +01:00
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
|
PRINTFLIKE(3, 4)
|
|
|
|
|
util_snprintf(char *str, size_t size, const char *format, ...)
|
|
|
|
|
{
|
|
|
|
|
va_list ap;
|
|
|
|
|
int ret;
|
|
|
|
|
va_start(ap, format);
|
|
|
|
|
ret = util_vsnprintf(str, size, format, ap);
|
|
|
|
|
va_end(ap);
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
2008-05-05 23:58:37 +09:00
|
|
|
|
2015-07-20 19:58:43 -04:00
|
|
|
static inline void
|
2015-07-22 13:21:24 +01:00
|
|
|
PRINTFLIKE(2, 3)
|
2008-05-05 23:58:37 +09:00
|
|
|
util_sprintf(char *str, const char *format, ...)
|
|
|
|
|
{
|
|
|
|
|
va_list ap;
|
|
|
|
|
va_start(ap, format);
|
|
|
|
|
util_vsnprintf(str, (size_t)-1, format, ap);
|
|
|
|
|
va_end(ap);
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-08 16:41:16 -06:00
|
|
|
static inline int
|
|
|
|
|
util_vasprintf(char **ret, const char *format, va_list ap)
|
|
|
|
|
{
|
|
|
|
|
va_list ap_copy;
|
|
|
|
|
|
|
|
|
|
/* Compute length of output string first */
|
|
|
|
|
va_copy(ap_copy, ap);
|
2018-09-06 17:43:52 +03:00
|
|
|
int r = util_vsnprintf(NULL, 0, format, ap_copy);
|
2017-09-08 16:41:16 -06:00
|
|
|
va_end(ap_copy);
|
|
|
|
|
|
|
|
|
|
if (r < 0)
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
|
|
*ret = (char *) malloc(r + 1);
|
2018-09-06 17:43:53 +03:00
|
|
|
if (!*ret)
|
2017-09-08 16:41:16 -06:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
|
|
/* Print to buffer */
|
|
|
|
|
return util_vsnprintf(*ret, r + 1, format, ap);
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-20 11:47:06 +00:00
|
|
|
#define strncat util_strncat
|
2015-07-20 19:58:43 -04:00
|
|
|
static inline char*
|
2008-05-05 23:58:37 +09:00
|
|
|
util_strncat(char *dst, const char *src, size_t n)
|
|
|
|
|
{
|
|
|
|
|
char *p = dst + strlen(dst);
|
|
|
|
|
const char *q = src;
|
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < n && *q != '\0'; ++i)
|
|
|
|
|
*p++ = *q++;
|
|
|
|
|
*p = '\0';
|
|
|
|
|
|
|
|
|
|
return dst;
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-20 19:58:43 -04:00
|
|
|
static inline int
|
2008-05-05 23:58:37 +09:00
|
|
|
util_strcmp(const char *s1, const char *s2)
|
|
|
|
|
{
|
|
|
|
|
unsigned char u1, u2;
|
|
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
|
u1 = (unsigned char) *s1++;
|
|
|
|
|
u2 = (unsigned char) *s2++;
|
|
|
|
|
if (u1 != u2)
|
|
|
|
|
return u1 - u2;
|
|
|
|
|
if (u1 == '\0')
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-20 11:48:38 +00:00
|
|
|
#define strncmp util_strncmp
|
2015-07-20 19:58:43 -04:00
|
|
|
static inline int
|
2008-05-05 23:58:37 +09:00
|
|
|
util_strncmp(const char *s1, const char *s2, size_t n)
|
|
|
|
|
{
|
|
|
|
|
unsigned char u1, u2;
|
|
|
|
|
|
|
|
|
|
while (n-- > 0) {
|
|
|
|
|
u1 = (unsigned char) *s1++;
|
|
|
|
|
u2 = (unsigned char) *s2++;
|
|
|
|
|
if (u1 != u2)
|
|
|
|
|
return u1 - u2;
|
|
|
|
|
if (u1 == '\0')
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-09-01 16:29:17 -06:00
|
|
|
#define util_strcasecmp stricmp
|
2018-11-20 11:42:14 +00:00
|
|
|
#define strdup _strdup
|
2015-09-01 16:29:17 -06:00
|
|
|
|
2008-04-14 23:55:36 +09:00
|
|
|
#else
|
2008-05-05 23:58:37 +09:00
|
|
|
|
2008-04-14 23:55:36 +09:00
|
|
|
#define util_vsnprintf vsnprintf
|
|
|
|
|
#define util_snprintf snprintf
|
2017-09-08 16:41:16 -06:00
|
|
|
#define util_vasprintf vasprintf
|
2008-05-06 09:07:11 +01:00
|
|
|
#define util_sprintf sprintf
|
2008-05-05 23:58:37 +09:00
|
|
|
#define util_strcmp strcmp
|
2015-09-01 16:29:17 -06:00
|
|
|
#define util_strcasecmp strcasecmp
|
2008-05-05 23:58:37 +09:00
|
|
|
|
2008-04-14 23:55:36 +09:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#endif /* U_STRING_H_ */
|