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