|
发表于 2009-10-30 11:06:50
|
显示全部楼层
在src/hal-0.5.13/hald/linux/probing/probe-volume.c中有关赋值volume_label的代码如下
[PHP] if (label[0] != '\0') {
char *volume_label;
/* we need to be sure for a utf8 valid label, because dbus accept only utf8 valid strings */
volume_label = strdup_valid_utf8 (label);
if( volume_label != NULL ) {
libhal_changeset_set_property_string (cs, "volume.label", volume_label);
HAL_DEBUG(("volume.label = '%s'", volume_label));
if (volume_label[0] != '\0') {
libhal_changeset_set_property_string (cs, "info.product", volume_label);
g_free(volume_label);
return;
}
g_free(volume_label);
}
}[/PHP]
[PHP]static gchar *
strdup_valid_utf8 (const char *str)
{
char *endchar;
char *newstr;
unsigned int fixes;
if (str == NULL)
return NULL;
newstr = g_strdup (str);
fixes = 0;
while (!g_utf8_validate (newstr, -1, (const char **) &endchar)) {
*endchar = '_';
++fixes;
}
/* If we had to fix more than 20% of the characters, give up */
if (fixes > 0 && g_utf8_strlen (newstr, -1) / fixes < 5) {
g_free (newstr);
newstr = g_strdup("");
}
return newstr;
}[/PHP] |
|