Selaa lähdekoodia

~/.bin/up.c: Fix lint errors

Lu Stadler 7 vuotta sitten
vanhempi
commit
5925a98667
1 muutettua tiedostoa jossa 12 lisäystä ja 7 poistoa
  1. 12 7
      .bin/up.c

+ 12 - 7
.bin/up.c

@ -3,23 +3,28 @@
3 3
#include <string.h>
4 4
#include <unistd.h>
5 5
6
#define MAX_PATH (2 << 8)
7
6 8
int main(int argc, char **argv) {
7 9
	if (argc < 2) {
8 10
		printf("Usage: %s file-or-dir\n", argv[0]);
9 11
		return -1;
10 12
	}
11 13
12
	int max_path = 2 << 8;
13
	char *path = malloc(sizeof(char) * max_path);
14
	int status = EXIT_FAILURE;
15
	char *path = malloc(sizeof(char) * MAX_PATH);
14 16
	do {
15
		getcwd(path, max_path);
17
		getcwd(path, MAX_PATH);
16 18
		if (access(argv[1], F_OK) == 0) {
17 19
			printf("%s\n", path);
18
			return 0;
19
		} else {
20
			chdir("..");
20
			status = EXIT_SUCCESS;
21
			goto exit;
21 22
		}
23
24
		chdir("..");
22 25
	} while (strcmp("/", path) != 0);
23 26
24
	return 1;
27
exit:
28
	free(path);
29
	return status;
25 30
}