Advertisement
Ai4rei

April Missions

Apr 22nd, 2014
412
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.29 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. /*
  6.     mission: str == "." || str == ".."
  7. */
  8.  
  9. int __stdcall isdot_1(const char* str)
  10. {
  11.     return strcmp(str, ".") == 0 || strcmp(str, "..") == 0;
  12. }
  13.  
  14. int __stdcall isdot_2(const char* str)
  15. {
  16.     return str[0] == '.' && ( str[1] == 0 || ( str[1] == '.' && str[2] == 0 ) );
  17. }
  18.  
  19. int __stdcall isdot_3(const char* str)
  20. {
  21.     /*
  22.         assumes:
  23.             - memory layout (little endian, 1-byte characters)
  24.     */
  25.     const unsigned short* buf = (const unsigned short*)str;
  26.  
  27.     return buf[0] == '.' || ( buf[0] == '..' && str[2] == 0 );
  28. }
  29.  
  30. int __stdcall isdot_4(const char* str)
  31. {
  32.     /*
  33.         assumes:
  34.             - memory layout (little endian, 1-byte characters)
  35.             - alignment and free access within alignment size
  36.     */
  37.     unsigned int val = ((unsigned int*)str)[0];
  38.  
  39.     val&= 0xffffff;
  40.  
  41.     return val=='..' || (unsigned short)val=='.';
  42. }
  43.  
  44. /*
  45.     mission: left(str,2) == "\\"
  46. */
  47.  
  48. int __stdcall isunc_1(const char* str)
  49. {
  50.     return strncmp(str, "\\\\", 2) == 0;
  51. }
  52.  
  53. int __stdcall isunc_2(const char* str)
  54. {
  55.     return str[0] == '\\' && str[1] == '\\';
  56. }
  57.  
  58. int __stdcall isunc_3(const char* str)
  59. {
  60.     /*
  61.         assumes:
  62.             - memory layout (1-byte characters)
  63.     */
  64.     const unsigned short* buf = (const unsigned short*)str;
  65.  
  66.     return buf[0] == '\\\\';
  67. }
  68.  
  69. /*
  70.     mission: left(wstr,2) == "\\"
  71. */
  72.  
  73. int __stdcall isuncw_1(const wchar_t* str)
  74. {
  75.     return wcsncmp(str, L"\\\\", 2) == 0;
  76. }
  77.  
  78. int __stdcall isuncw_2(const wchar_t* str)
  79. {
  80.     return str[0] == '\\' && str[1] == '\\';
  81. }
  82.  
  83. int __stdcall isuncw_3(const wchar_t* str)
  84. {
  85.     /*
  86.         assumes:
  87.             - memory layout (2-byte characters)
  88.     */
  89.     const unsigned long* buf = (const unsigned long*)str;
  90.  
  91.     return buf[0] == ( ( '\\' << 16 ) | '\\' );
  92. }
  93.  
  94. int main(int argc, char** argv)
  95. {
  96.     char* arg = argv[1];
  97.     wchar_t* wrg = (wchar_t*)argc;
  98.  
  99.     if(isdot_1(arg)) return 1;
  100.     if(isdot_2(arg)) return 2;
  101.     if(isdot_3(arg)) return 3;
  102.     if(isdot_4(arg)) return 4;
  103.  
  104.     if(isunc_1(arg)) return 1;
  105.     if(isunc_2(arg)) return 2;
  106.     if(isunc_3(arg)) return 3;
  107.  
  108.     if(isuncw_1(wrg)) return 1;
  109.     if(isuncw_2(wrg)) return 2;
  110.     if(isuncw_3(wrg)) return 3;
  111.  
  112.     return 0;
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement