Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- /*
- mission: str == "." || str == ".."
- */
- int __stdcall isdot_1(const char* str)
- {
- return strcmp(str, ".") == 0 || strcmp(str, "..") == 0;
- }
- int __stdcall isdot_2(const char* str)
- {
- return str[0] == '.' && ( str[1] == 0 || ( str[1] == '.' && str[2] == 0 ) );
- }
- int __stdcall isdot_3(const char* str)
- {
- /*
- assumes:
- - memory layout (little endian, 1-byte characters)
- */
- const unsigned short* buf = (const unsigned short*)str;
- return buf[0] == '.' || ( buf[0] == '..' && str[2] == 0 );
- }
- int __stdcall isdot_4(const char* str)
- {
- /*
- assumes:
- - memory layout (little endian, 1-byte characters)
- - alignment and free access within alignment size
- */
- unsigned int val = ((unsigned int*)str)[0];
- val&= 0xffffff;
- return val=='..' || (unsigned short)val=='.';
- }
- /*
- mission: left(str,2) == "\\"
- */
- int __stdcall isunc_1(const char* str)
- {
- return strncmp(str, "\\\\", 2) == 0;
- }
- int __stdcall isunc_2(const char* str)
- {
- return str[0] == '\\' && str[1] == '\\';
- }
- int __stdcall isunc_3(const char* str)
- {
- /*
- assumes:
- - memory layout (1-byte characters)
- */
- const unsigned short* buf = (const unsigned short*)str;
- return buf[0] == '\\\\';
- }
- /*
- mission: left(wstr,2) == "\\"
- */
- int __stdcall isuncw_1(const wchar_t* str)
- {
- return wcsncmp(str, L"\\\\", 2) == 0;
- }
- int __stdcall isuncw_2(const wchar_t* str)
- {
- return str[0] == '\\' && str[1] == '\\';
- }
- int __stdcall isuncw_3(const wchar_t* str)
- {
- /*
- assumes:
- - memory layout (2-byte characters)
- */
- const unsigned long* buf = (const unsigned long*)str;
- return buf[0] == ( ( '\\' << 16 ) | '\\' );
- }
- int main(int argc, char** argv)
- {
- char* arg = argv[1];
- wchar_t* wrg = (wchar_t*)argc;
- if(isdot_1(arg)) return 1;
- if(isdot_2(arg)) return 2;
- if(isdot_3(arg)) return 3;
- if(isdot_4(arg)) return 4;
- if(isunc_1(arg)) return 1;
- if(isunc_2(arg)) return 2;
- if(isunc_3(arg)) return 3;
- if(isuncw_1(wrg)) return 1;
- if(isuncw_2(wrg)) return 2;
- if(isuncw_3(wrg)) return 3;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement