mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 13:45:38 +00:00
virIndexToDiskName: Use g_string_prepend(_c) to improve readability
Use a dynamic string helper so that we don't have to calculate the string lengths and then iterate from the rear. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
3b5eab6e25
commit
ec809ba4ed
@ -432,24 +432,15 @@ int virDiskNameToIndex(const char *name)
|
||||
|
||||
char *virIndexToDiskName(unsigned int idx, const char *prefix)
|
||||
{
|
||||
char *name = NULL;
|
||||
size_t i;
|
||||
int ctr;
|
||||
int offset;
|
||||
GString *str = g_string_new(NULL);
|
||||
long long ctr;
|
||||
|
||||
for (i = 0, ctr = idx; ctr >= 0; ++i, ctr = ctr / 26 - 1) { }
|
||||
for (ctr = idx; ctr >= 0; ctr = ctr / 26 - 1)
|
||||
g_string_prepend_c(str, 'a' + (ctr % 26));
|
||||
|
||||
offset = strlen(prefix);
|
||||
g_string_prepend(str, prefix);
|
||||
|
||||
name = g_new0(char, offset + i + 1);
|
||||
|
||||
strcpy(name, prefix);
|
||||
name[offset + i] = '\0';
|
||||
|
||||
for (i = i - 1, ctr = idx; ctr >= 0; --i, ctr = ctr / 26 - 1)
|
||||
name[offset + i] = 'a' + (ctr % 26);
|
||||
|
||||
return name;
|
||||
return g_string_free(str, false);
|
||||
}
|
||||
|
||||
#ifndef AI_CANONIDN
|
||||
|
Loading…
Reference in New Issue
Block a user