Move hex_digits to rodata

Turn a string into a constant array.
This commit is contained in:
Matthias Clasen 2009-04-03 00:35:43 -04:00
parent 25ff8ee748
commit e6e82c51a6

View File

@ -359,17 +359,17 @@ escape_byte_string (const char *str)
int num_invalid, i;
char *escaped_val, *p;
unsigned char c;
char *hex_digits = "0123456789abcdef";
const char hex_digits[] = "0123456789abcdef";
len = strlen (str);
num_invalid = 0;
for (i = 0; i < len; i++)
{
if (!valid_char (str[i]))
num_invalid++;
}
if (num_invalid == 0)
return g_strdup (str);
else
@ -396,15 +396,15 @@ escape_byte_string (const char *str)
}
/*
* g_file_attribute_value_as_string:
* _g_file_attribute_value_as_string:
* @attr: a #GFileAttributeValue.
*
* Converts a #GFileAttributeValue to a string for display.
* The returned string should be freed when no longer needed.
*
* Returns: a string from the @attr, %NULL on error, or "&lt;invalid&gt;"
*
* Returns: a string from the @attr, %NULL on error, or "&lt;invalid&gt;"
* if @attr is of type %G_FILE_ATTRIBUTE_TYPE_INVALID.
**/
*/
char *
_g_file_attribute_value_as_string (const GFileAttributeValue *attr)
{
@ -445,19 +445,19 @@ _g_file_attribute_value_as_string (const GFileAttributeValue *attr)
str = g_strdup ("<invalid>");
break;
}
return str;
}
/*
* g_file_attribute_value_get_string:
* _g_file_attribute_value_get_string:
* @attr: a #GFileAttributeValue.
*
*
* Gets the string from a file attribute value. If the value is not the
* right type then %NULL will be returned.
*
*
* Returns: the string value contained within the attribute, or %NULL.
**/
*/
const char *
_g_file_attribute_value_get_string (const GFileAttributeValue *attr)
{
@ -470,14 +470,14 @@ _g_file_attribute_value_get_string (const GFileAttributeValue *attr)
}
/*
* g_file_attribute_value_get_byte_string:
* _g_file_attribute_value_get_byte_string:
* @attr: a #GFileAttributeValue.
*
*
* Gets the byte string from a file attribute value. If the value is not the
* right type then %NULL will be returned.
*
*
* Returns: the byte string contained within the attribute or %NULL.
**/
*/
const char *
_g_file_attribute_value_get_byte_string (const GFileAttributeValue *attr)
{
@ -488,16 +488,16 @@ _g_file_attribute_value_get_byte_string (const GFileAttributeValue *attr)
return attr->u.string;
}
/*
* g_file_attribute_value_get_boolean:
* _g_file_attribute_value_get_boolean:
* @attr: a #GFileAttributeValue.
*
*
* Gets the boolean value from a file attribute value. If the value is not the
* right type then %FALSE will be returned.
*
*
* Returns: the boolean value contained within the attribute, or %FALSE.
**/
*/
gboolean
_g_file_attribute_value_get_boolean (const GFileAttributeValue *attr)
{
@ -508,16 +508,16 @@ _g_file_attribute_value_get_boolean (const GFileAttributeValue *attr)
return attr->u.boolean;
}
/*
* g_file_attribute_value_get_uint32:
* _g_file_attribute_value_get_uint32:
* @attr: a #GFileAttributeValue.
*
* Gets the unsigned 32-bit integer from a file attribute value. If the value
* is not the right type then %0 will be returned.
*
* Returns: the unsigned 32-bit integer from the attribute, or %0.
**/
*
* Gets the unsigned 32-bit integer from a file attribute value. If the value
* is not the right type then 0 will be returned.
*
* Returns: the unsigned 32-bit integer from the attribute, or 0.
*/
guint32
_g_file_attribute_value_get_uint32 (const GFileAttributeValue *attr)
{
@ -530,14 +530,14 @@ _g_file_attribute_value_get_uint32 (const GFileAttributeValue *attr)
}
/*
* g_file_attribute_value_get_int32:
* _g_file_attribute_value_get_int32:
* @attr: a #GFileAttributeValue.
*
* Gets the signed 32-bit integer from a file attribute value. If the value
* is not the right type then %0 will be returned.
*
* Returns: the signed 32-bit integer from the attribute, or %0.
**/
*
* Gets the signed 32-bit integer from a file attribute value. If the value
* is not the right type then 0 will be returned.
*
* Returns: the signed 32-bit integer from the attribute, or 0.
*/
gint32
_g_file_attribute_value_get_int32 (const GFileAttributeValue *attr)
{
@ -550,14 +550,14 @@ _g_file_attribute_value_get_int32 (const GFileAttributeValue *attr)
}
/*
* g_file_attribute_value_get_uint64:
* _g_file_attribute_value_get_uint64:
* @attr: a #GFileAttributeValue.
*
* Gets the unsigned 64-bit integer from a file attribute value. If the value
* is not the right type then %0 will be returned.
*
* Returns: the unsigned 64-bit integer from the attribute, or %0.
**/
*
* Gets the unsigned 64-bit integer from a file attribute value. If the value
* is not the right type then 0 will be returned.
*
* Returns: the unsigned 64-bit integer from the attribute, or 0.
*/
guint64
_g_file_attribute_value_get_uint64 (const GFileAttributeValue *attr)
{
@ -570,14 +570,14 @@ _g_file_attribute_value_get_uint64 (const GFileAttributeValue *attr)
}
/*
* g_file_attribute_value_get_int64:
* _g_file_attribute_value_get_int64:
* @attr: a #GFileAttributeValue.
*
* Gets the signed 64-bit integer from a file attribute value. If the value
* is not the right type then %0 will be returned.
*
* Returns: the signed 64-bit integer from the attribute, or %0.
**/
*
* Gets the signed 64-bit integer from a file attribute value. If the value
* is not the right type then 0 will be returned.
*
* Returns: the signed 64-bit integer from the attribute, or 0.
*/
gint64
_g_file_attribute_value_get_int64 (const GFileAttributeValue *attr)
{
@ -590,13 +590,13 @@ _g_file_attribute_value_get_int64 (const GFileAttributeValue *attr)
}
/*
* g_file_attribute_value_get_object:
* _g_file_attribute_value_get_object:
* @attr: a #GFileAttributeValue.
*
* Gets the GObject from a file attribute value. If the value
*
* Gets the GObject from a file attribute value. If the value
* is not the right type then %NULL will be returned.
*
* Returns: the GObject from the attribute, or %0.
*
* Returns: the GObject from the attribute, or %NULL.
**/
GObject *
_g_file_attribute_value_get_object (const GFileAttributeValue *attr)
@ -627,30 +627,30 @@ _g_file_attribute_value_set_from_pointer (GFileAttributeValue *value,
else
value->u.string = value_p;
break;
case G_FILE_ATTRIBUTE_TYPE_OBJECT:
if (dup)
value->u.obj = g_object_ref (value_p);
else
value->u.obj = value_p;
break;
case G_FILE_ATTRIBUTE_TYPE_BOOLEAN:
value->u.boolean = *(gboolean *)value_p;
break;
case G_FILE_ATTRIBUTE_TYPE_UINT32:
value->u.uint32 = *(guint32 *)value_p;
break;
case G_FILE_ATTRIBUTE_TYPE_INT32:
value->u.int32 = *(gint32 *)value_p;
break;
case G_FILE_ATTRIBUTE_TYPE_UINT64:
value->u.uint64 = *(guint64 *)value_p;
break;
case G_FILE_ATTRIBUTE_TYPE_INT64:
value->u.int64 = *(gint64 *)value_p;
break;
@ -659,15 +659,14 @@ _g_file_attribute_value_set_from_pointer (GFileAttributeValue *value,
break;
}
}
/*
* g_file_attribute_value_set_string:
* _g_file_attribute_value_set_string:
* @attr: a #GFileAttributeValue.
* @string: a string to set within the type.
*
*
* Sets the attribute value to a given string.
*
**/
*/
void
_g_file_attribute_value_set_string (GFileAttributeValue *attr,
const char *string)
@ -681,13 +680,12 @@ _g_file_attribute_value_set_string (GFileAttributeValue *attr,
}
/*
* g_file_attribute_value_set_byte_string:
* _g_file_attribute_value_set_byte_string:
* @attr: a #GFileAttributeValue.
* @string: a byte string to set within the type.
*
*
* Sets the attribute value to a given byte string.
*
**/
*/
void
_g_file_attribute_value_set_byte_string (GFileAttributeValue *attr,
const char *string)
@ -701,13 +699,12 @@ _g_file_attribute_value_set_byte_string (GFileAttributeValue *attr,
}
/*
* g_file_attribute_value_set_boolean:
* _g_file_attribute_value_set_boolean:
* @attr: a #GFileAttributeValue.
* @value: a #gboolean to set within the type.
*
* Sets the attribute value to the given boolean value.
*
**/
*
* Sets the attribute value to the given boolean value.
*/
void
_g_file_attribute_value_set_boolean (GFileAttributeValue *attr,
gboolean value)
@ -720,32 +717,30 @@ _g_file_attribute_value_set_boolean (GFileAttributeValue *attr,
}
/*
* g_file_attribute_value_set_uint32:
* _g_file_attribute_value_set_uint32:
* @attr: a #GFileAttributeValue.
* @value: a #guint32 to set within the type.
*
*
* Sets the attribute value to the given unsigned 32-bit integer.
*
**/
*/
void
_g_file_attribute_value_set_uint32 (GFileAttributeValue *attr,
guint32 value)
{
g_return_if_fail (attr != NULL);
_g_file_attribute_value_clear (attr);
attr->type = G_FILE_ATTRIBUTE_TYPE_UINT32;
attr->u.uint32 = value;
}
/*
* g_file_attribute_value_set_int32:
* _g_file_attribute_value_set_int32:
* @attr: a #GFileAttributeValue.
* @value: a #gint32 to set within the type.
*
*
* Sets the attribute value to the given signed 32-bit integer.
*
**/
*/
void
_g_file_attribute_value_set_int32 (GFileAttributeValue *attr,
gint32 value)
@ -758,13 +753,12 @@ _g_file_attribute_value_set_int32 (GFileAttributeValue *attr,
}
/*
* g_file_attribute_value_set_uint64:
* _g_file_attribute_value_set_uint64:
* @attr: a #GFileAttributeValue.
* @value: a #guint64 to set within the type.
*
*
* Sets the attribute value to a given unsigned 64-bit integer.
*
**/
*/
void
_g_file_attribute_value_set_uint64 (GFileAttributeValue *attr,
guint64 value)
@ -777,13 +771,12 @@ _g_file_attribute_value_set_uint64 (GFileAttributeValue *attr,
}
/*
* g_file_attribute_value_set_int64:
* _g_file_attribute_value_set_int64:
* @attr: a #GFileAttributeValue.
* @value: a #gint64 to set within the type.
*
* Sets the attribute value to a given signed 64-bit integer.
*
**/
*
* Sets the attribute value to a given signed 64-bit integer.
*/
void
_g_file_attribute_value_set_int64 (GFileAttributeValue *attr,
gint64 value)
@ -796,14 +789,13 @@ _g_file_attribute_value_set_int64 (GFileAttributeValue *attr,
}
/*
* g_file_attribute_value_set_object:
* _g_file_attribute_value_set_object:
* @attr: a #GFileAttributeValue.
* @obj: a #GObject.
*
* Sets the attribute to contain the value @obj.
* The @attr references the GObject internally.
*
**/
*/
void
_g_file_attribute_value_set_object (GFileAttributeValue *attr,
GObject *obj)
@ -831,40 +823,40 @@ list_update_public (GFileAttributeInfoListPriv *priv)
/**
* g_file_attribute_info_list_new:
*
*
* Creates a new file attribute info list.
*
*
* Returns: a #GFileAttributeInfoList.
**/
*/
GFileAttributeInfoList *
g_file_attribute_info_list_new (void)
{
GFileAttributeInfoListPriv *priv;
priv = g_new0 (GFileAttributeInfoListPriv, 1);
priv->ref_count = 1;
priv->array = g_array_new (TRUE, FALSE, sizeof (GFileAttributeInfo));
list_update_public (priv);
return (GFileAttributeInfoList *)priv;
}
/**
* g_file_attribute_info_list_dup:
* @list: a #GFileAttributeInfoList to duplicate.
*
*
* Makes a duplicate of a file attribute info list.
*
* Returns: a copy of the given @list.
**/
*
* Returns: a copy of the given @list.
*/
GFileAttributeInfoList *
g_file_attribute_info_list_dup (GFileAttributeInfoList *list)
{
GFileAttributeInfoListPriv *new;
int i;
g_return_val_if_fail (list != NULL, NULL);
new = g_new0 (GFileAttributeInfoListPriv, 1);
@ -879,47 +871,47 @@ g_file_attribute_info_list_dup (GFileAttributeInfoList *list)
new->public.infos[i].type = list->infos[i].type;
new->public.infos[i].flags = list->infos[i].flags;
}
return (GFileAttributeInfoList *)new;
}
/**
* g_file_attribute_info_list_ref:
* @list: a #GFileAttributeInfoList to reference.
*
*
* References a file attribute info list.
*
*
* Returns: #GFileAttributeInfoList or %NULL on error.
**/
*/
GFileAttributeInfoList *
g_file_attribute_info_list_ref (GFileAttributeInfoList *list)
{
GFileAttributeInfoListPriv *priv = (GFileAttributeInfoListPriv *)list;
g_return_val_if_fail (list != NULL, NULL);
g_return_val_if_fail (priv->ref_count > 0, NULL);
g_atomic_int_inc (&priv->ref_count);
return list;
}
/**
* g_file_attribute_info_list_unref:
* @list: The #GFileAttributeInfoList to unreference.
*
*
* Removes a reference from the given @list. If the reference count
* falls to zero, the @list is deleted.
**/
*/
void
g_file_attribute_info_list_unref (GFileAttributeInfoList *list)
{
GFileAttributeInfoListPriv *priv = (GFileAttributeInfoListPriv *)list;
int i;
g_return_if_fail (list != NULL);
g_return_if_fail (priv->ref_count > 0);
if (g_atomic_int_dec_and_test (&priv->ref_count))
{
for (i = 0; i < list->n_infos; i++)
@ -933,7 +925,7 @@ g_file_attribute_info_list_bsearch (GFileAttributeInfoList *list,
const char *name)
{
int start, end, mid;
start = 0;
end = list->n_infos;
@ -955,26 +947,26 @@ g_file_attribute_info_list_bsearch (GFileAttributeInfoList *list,
* g_file_attribute_info_list_lookup:
* @list: a #GFileAttributeInfoList.
* @name: the name of the attribute to lookup.
*
*
* Gets the file attribute with the name @name from @list.
*
* Returns: a #GFileAttributeInfo for the @name, or %NULL if an
* Returns: a #GFileAttributeInfo for the @name, or %NULL if an
* attribute isn't found.
**/
*/
const GFileAttributeInfo *
g_file_attribute_info_list_lookup (GFileAttributeInfoList *list,
const char *name)
{
int i;
g_return_val_if_fail (list != NULL, NULL);
g_return_val_if_fail (name != NULL, NULL);
i = g_file_attribute_info_list_bsearch (list, name);
if (i < list->n_infos && strcmp (list->infos[i].name, name) == 0)
return &list->infos[i];
return NULL;
}
@ -984,20 +976,20 @@ g_file_attribute_info_list_lookup (GFileAttributeInfoList *list,
* @name: the name of the attribute to add.
* @type: the #GFileAttributeType for the attribute.
* @flags: #GFileAttributeInfoFlags for the attribute.
*
*
* Adds a new attribute with @name to the @list, setting
* its @type and @flags.
**/
* its @type and @flags.
*/
void
g_file_attribute_info_list_add (GFileAttributeInfoList *list,
const char *name,
GFileAttributeType type,
GFileAttributeInfoFlags flags)
g_file_attribute_info_list_add (GFileAttributeInfoList *list,
const char *name,
GFileAttributeType type,
GFileAttributeInfoFlags flags)
{
GFileAttributeInfoListPriv *priv = (GFileAttributeInfoListPriv *)list;
GFileAttributeInfo info;
int i;
g_return_if_fail (list != NULL);
g_return_if_fail (name != NULL);