-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhdfs_url.c
54 lines (41 loc) · 1.08 KB
/
hdfs_url.c
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
48
49
50
51
52
53
54
#define _GNU_SOURCE
#include "hdfs.h"
#include "hdfs_url.h"
#include <mpi.h>
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <stdlib.h>
int hdfs_url_parse(const char *filename, char *hdfs_fsname, int fsname_buf_len,
char *hdfs_filename, int filename_buf_len)
{
int len, i, ret;
char *tmp;
char prot[100];
char host[1000];
int port;
char port_str[100];
char path[1000];
len = strlen(filename);
tmp = malloc(len + 1);
strcpy(tmp, filename);
for (i=0; i < len; i++) {
if (tmp[i] == ':')
tmp[i] = ' ';
}
ret = sscanf(tmp, "%99s //%999s %d%999s[^\n]", prot, host, &port, path);
if (ret < 4)
return -1;
if (strcmp(prot, "hdfs"))
return -1;
// Reconstruct the HDFS file system name
strcpy(hdfs_fsname, prot);//, fsname_buf_len);
strcat(hdfs_fsname, "://");//, fsname_buf_len);
strcat(hdfs_fsname, host);//, fsname_buf_len);
strcat(hdfs_fsname, ":");//, fsname_buf_len);
printf("%d\n", port);
sprintf(port_str, "%d", port);
strcat(hdfs_fsname, port_str);//, fsname_buf_len);
strcpy(hdfs_filename, path);//, filename_buf_len);
return 0;
}