File: partname.c

package info (click to toggle)
loop-aes-utils 2.12p-4sarge2
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 8,644 kB
  • ctags: 5,072
  • sloc: ansic: 46,123; sh: 7,606; makefile: 884; perl: 86; csh: 62; sed: 55
file content (47 lines) | stat: -rw-r--r-- 889 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <ctype.h>
#include <stdio.h>
#include <string.h>
#include "common.h"

/*
 * return partition name - uses static storage unless buf is supplied
 */
static char *
partnamebf(char *dev, int pno, int lth, int bufsiz, char *bufp) {
	static char buffer[80];
	char *p;
	int w, wp;

	if (!bufp) {
		bufp = buffer;
		bufsiz = sizeof(buffer);
	}

	w = strlen(dev);
	p = "";

	if (isdigit(dev[w-1]))
		p = "p";

	/* devfs kludge - note: fdisk partition names are not supposed
	   to equal kernel names, so there is no reason to do this */
	if (strcmp (dev + w - 4, "disc") == 0) {
		w -= 4;
		p = "part";
	}

	wp = strlen(p);
		
	if (lth) {
		snprintf(bufp, bufsiz, "%*.*s%s%-2u",
			 lth-wp-2, w, dev, p, pno);
	} else {
		snprintf(bufp, bufsiz, "%.*s%s%-2u", w, dev, p, pno);
	}
	return bufp;
}

char *
partname(char *dev, int pno, int lth) {
	return partnamebf(dev, pno, lth, 0, NULL);
}