Initial public busybox maemo commit, 3:1.10.2.legal-1osso12
[busybox4maemo] / debian / sfdisk / partname.c
1 #include <ctype.h>
2 #include <stdio.h>
3 #include <string.h>
4 #include "common.h"
5
6 /*
7  * return partition name - uses static storage unless buf is supplied
8  */
9 static char *
10 partnamebf(char *dev, int pno, int lth, int bufsiz, char *bufp) {
11         static char buffer[80];
12         char *p;
13         int w, wp;
14
15         if (!bufp) {
16                 bufp = buffer;
17                 bufsiz = sizeof(buffer);
18         }
19
20         w = strlen(dev);
21         p = "";
22
23         if (isdigit(dev[w-1]))
24                 p = "p";
25
26         /* devfs kludge - note: fdisk partition names are not supposed
27            to equal kernel names, so there is no reason to do this */
28         if (strcmp (dev + w - 4, "disc") == 0) {
29                 w -= 4;
30                 p = "part";
31         }
32
33         wp = strlen(p);
34                 
35         if (lth) {
36                 snprintf(bufp, bufsiz, "%*.*s%s%-2u",
37                          lth-wp-2, w, dev, p, pno);
38         } else {
39                 snprintf(bufp, bufsiz, "%.*s%s%-2u", w, dev, p, pno);
40         }
41         return bufp;
42 }
43
44 char *
45 partname(char *dev, int pno, int lth) {
46         return partnamebf(dev, pno, lth, 0, NULL);
47 }