-
Notifications
You must be signed in to change notification settings - Fork 3
Implementation for sys/stat.h #59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: devs/expertise/native-windows
Are you sure you want to change the base?
Changes from all commits
fe4ab56
a50025d
cfe5040
ad3709f
a8fa408
5c8ca71
3c9df9a
6f33c48
89c457c
2bad3e7
4c3d41f
6371434
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| #include <stdio.h> | ||
| #include <stdlib.h> | ||
| #include <string.h> | ||
| #include "evil_private.h" | ||
| #include <evil_api.h> | ||
| #include <sys/types.h> | ||
| #include <sys/stat.h> | ||
| #include "evil_stat.h" | ||
|
|
||
| #define AT_SYMLINK_NOFOLLOW 0x01 | ||
|
|
||
| EVIL_API int | ||
| fstatat(int dirfd, const char *pathname, struct stat *statbuf, int flags) | ||
| { | ||
| int r_fstatat; | ||
|
|
||
| if (pathname[1] == ':' && pathname[2] == '\\' || pathname[2] == '/' ) | ||
| { | ||
| if (flags == AT_SYMLINK_NOFOLLOW) | ||
| r_fstatat = stat(pathname, statbuf); | ||
| else | ||
| r_fstatat = stat(pathname, statbuf); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why the |
||
| return r_fstatat; | ||
| } | ||
| else | ||
| { | ||
| char *pathbuf = NULL; | ||
| size_t pathbuf_size = 0; | ||
| DWORD copied = 0; | ||
| do | ||
| { | ||
| pathbuf_size += MAX_PATH; | ||
| pathbuf = realloc(pathbuf, pathbuf_size * sizeof(char)); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The memory allocated here is never freed. |
||
| copied = GetModuleFileName(NULL, pathbuf, pathbuf_size); | ||
| } while (copied >= pathbuf_size); | ||
|
|
||
| int size_str; | ||
| for (size_str = strlen(pathbuf) -1; size_str >= 0; size_str --) | ||
| { | ||
| if (pathbuf[size_str] == '\\') | ||
| { | ||
| pathbuf[size_str + 1] = 0; | ||
| break; | ||
| } | ||
| } | ||
ricardocvel marked this conversation as resolved.
Show resolved
Hide resolved
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about using |
||
|
|
||
| size_str = strlen(pathbuf) + strlen(pathname); | ||
| char *path_complete = malloc(sizeof(char) * size_str + 1); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The memory allocated here is never freed. |
||
| strcpy(path_complete, pathbuf); | ||
| strcat(path_complete, pathname); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What if |
||
|
|
||
| if (flags == AT_SYMLINK_NOFOLLOW) | ||
| { | ||
| r_fstatat = stat(path_complete, statbuf); | ||
| } | ||
| else | ||
| { | ||
| r_fstatat = stat(path_complete, statbuf); | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why the |
||
| return r_fstatat; | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You must check the buffer size before accessing it.