Created
March 22, 2015 21:06
-
-
Save reportbase/e9e8b0a93f80197e7f34 to your computer and use it in GitHub Desktop.
returns the path queue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
DT_BLK This is a block device. | |
DT_CHR This is a character device. | |
DT_DIR This is a directory. | |
DT_FIFO This is a named pipe (FIFO). | |
DT_LNK This is a symbolic link. | |
DT_REG This is a regular file. | |
DT_SOCK This is a UNIX domain socket. | |
DT_UNKNOWN The file type is unknown. | |
*/ | |
//path - path to files. not filter. | |
inline queue<char*>* get_path_queue(const char* path, int type, | |
int& size, node<message*>** errors = NULL) | |
{ | |
DIR* dir; | |
if(!(dir = opendir(path))) | |
{ | |
push_message(errors, 0, 0, 1, __FILE__, __PRETTY_FUNCTION__, __LINE__, "bad path: %s", path); | |
return 0; | |
} | |
typedef queue<char*> queue_t; | |
queue_t* q = (queue_t*) malloc(sizeof(queue_t)); | |
memset(q, 0, sizeof(queue_t)); | |
struct dirent* ent; | |
while((ent = readdir(dir))) | |
{ | |
if(ent->d_type != type) | |
continue; | |
node<char*>* n = (node<char*>*) malloc(sizeof(node<char*>)); | |
memset(n, 0, sizeof(node<char*>)); | |
char fpath[MAX_PATH]; | |
sprintf(fpath, "%s/%s", path, ent->d_name); | |
n->data = (char*) malloc(MAX_PATH); | |
strcpy(n->data, fpath); | |
if(!q->tail) | |
{ | |
q->head = n; | |
q->tail = n; | |
} | |
else | |
{ | |
q->tail->next = n; | |
q->tail = n; | |
} | |
size++; | |
} | |
closedir(dir); | |
return q; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment