Ver Código Fonte

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

Lu Stadler 7 anos atrás
pai
commit
5925a98667
1 arquivos alterados com 12 adições e 7 exclusões
  1. 12 7
      .bin/up.c

+ 12 - 7
.bin/up.c

3
#include <string.h>
3
#include <string.h>
4
#include <unistd.h>
4
#include <unistd.h>
5
5
6
#define MAX_PATH (2 << 8)
7
6
int main(int argc, char **argv) {
8
int main(int argc, char **argv) {
7
	if (argc < 2) {
9
	if (argc < 2) {
8
		printf("Usage: %s file-or-dir\n", argv[0]);
10
		printf("Usage: %s file-or-dir\n", argv[0]);
9
		return -1;
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
	do {
16
	do {
15
		getcwd(path, max_path);
17
		getcwd(path, MAX_PATH);
16
		if (access(argv[1], F_OK) == 0) {
18
		if (access(argv[1], F_OK) == 0) {
17
			printf("%s\n", path);
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
	} while (strcmp("/", path) != 0);
25
	} while (strcmp("/", path) != 0);
23
26
24
	return 1;
27
exit:
28
	free(path);
29
	return status;
25
}
30
}