1. Си / Говнокод #23235

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    #include <stdio.h>
    #include <sys/types.h>
    #include <sys/stat.h>
    #include <fcntl.h>
    #include <unistd.h>
    
    int checkFile(char *s)
    {
    	return ( open(s, O_RDONLY, 0) == -1) ? 0 : 1;
    }
    
    int main(int argc, char *argv[])
    {
    	if(argc != 2) { printf("Тут один аргумент важен хуле\n"); return 1; }
    	if(checkFile(argv[1]))
    	{
    		int fd = open(argv[1], O_RDONLY, 0);
    		char buffer[1024];
    		read(fd, &buffer, sizeof(buffer));
    		printf("%s\n", buffer);
    		if( close(fd) == -1) perror("close");
    	}
    	else
    		printf("Файл не существует\n");
    	return 0;
    }

    Моя альтернатива программе cat, отсасывай cat ябучий!!

    Bro-C, 02 Августа 2017

    Комментарии (20)
  2. Си / Говнокод #23227

    −1

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    81. 81
    82. 82
    83. 83
    84. 84
    85. 85
    86. 86
    87. 87
    88. 88
    89. 89
    90. 90
    91. 91
    92. 92
    93. 93
    94. 94
    95. 95
    96. 96
    97. 97
    98. 98
    99. 99
    BYTE1 *GetLanguageCodeString( BYTE1	upper, BYTE1 lower , BYTE1  *lang_idx )
    {
    	int index = 0;
    	
    	switch(upper){
    		case 'a' :
    			switch(lower){
    				case 'a' : index = 0; break;
    				case 'b' : index = 1; break;
    				case 'f' : index = 2; break;
    				case 'm': index = 3; break;
    				case 'r': index = 4; break;
    				case 's': index = 5; break;
    				case 'y': index = 6; break;
    				case 'z': index = 7; break;
    				default: break;
    			}
    			break;
    		case 'b' :
    			switch(lower){
    				case 'a' : index = 8; break;
    				case 'e' : index = 9; break;
    				case 'g' : index = 10; break;
    				case 'h': index = 11; break;
    				case 'i': index = 12; break;
    				case 'n': index = 13; break;
    				case 'o': index = 14; break;
    				case 's': index = 136; break;	/* Added in SEIN 2004.04.01 KTJ */
    				default: break;
    			}
    			break;
    		case 'c' :
    			switch(lower){
    				case 'a' : index = 15; break;
    				case 'o' : index = 16; break;
    				case 's' : index = 17; break;
    				case 'y': index = 18; break;
    				default: break;
    			}
    			break;
    		case 'd' :
    			switch(lower){
    				case 'a' : index = 19; break;
    				case 'e' : index = 20; break;
    				case 'z' : index = 21; break;
    				default: break;
    			}
    			break;			
    		case 'e' :
    			switch(lower){
    				case 'l' : index = 22; break;
    				case 'n' : index = 23; break;
    				case 'o' : index = 24; break;
    				case 's': index = 25; break;
    				case 't': index = 26; break;
    				case 'u': index = 27; break;
    				break;
    			}
    			break;
    		case 'f' :
    			switch(lower){
    				case 'a' : index = 28; break;
    				case 'i' : index = 29; break;
    				case 'j' : index = 30; break;
    				case 'o': index = 31; break;
    				case 'r': index = 32; break;
    				case 'y': index = 33; break;
    				default: break;
    			}
    			break;
    		case 'g' :
    			switch(lower){
    				case 'a' : index = 34; break;
    				case 'd' : index = 35; break;
    				case 'l' : index = 36; break;
    				case 'n': index = 37; break;
    				case 'u': index = 38; break;
    				default: break;
    			}
    			break;
    		case 'h' :
    			switch(lower){
    				case 'a' : index = 39; break;
    				case 'e' : index = 40; break;
    				case 'i' : index = 41; break;
    				case 'r': index = 42; break;
    				case 'u': index = 43; break;
    				case 'y': index = 44; break;				
    				default: break;
    			}
    			break;			
    		case 'i' :
    			switch(lower){
    				case 'a' : index = 45; break;
    				case 'd' : index = 46; break;
    				case 'k': index = 47; break;
    				case 'n': index = 48; break;				
    				case 's': index = 49; break;
    				case 't': index = 50; break;

    питушня на switch для распознавания какой-то фигни с буквами

    j123123, 30 Июля 2017

    Комментарии (121)
  3. Си / Говнокод #23225

    +1

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    #define SPLICE(a,b) a##b
    #define LL(a,b) SPLICE(a,b)
    #define M(name) LL(NS,name)
    
    
    #define NS ns1_
    
    void M(somefunction)(){
    }
    
    #undef NS
    
    
    #define NS ns2_
    
    void M(somefunction)(){
    }
    
    #undef NS
    
    
    #define NS ns3_
    
    void M(somefunction)(){
    }
    
    #undef NS

    неймспейсы в Си на препроцессоре

    j123123, 30 Июля 2017

    Комментарии (8)
  4. Си / Говнокод #23224

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    #include <stdio.h>
    
    typedef int (*FUNC)();
    
    FUNC test (int a, int b){
        int ret(){
            return a + b;
        }
    
        return ret;
    }
    
    int main(){
        printf("%i\n", test(40, 2)());
        return 0;
    }
    
    
    /* Тоже самое на JS */
    function test(a, b){
        function ret(){
            return a + b;
        }
    
        return ret;
    }
    
    alert(test(40, 2)());
    
    
    # Тоже самое на Python
    def test(a, b):
        def ret():
            return a + b
    
        return ret
    
    print test(40, 2)()

    Странно работает компилятор, версия: gcc version 4.7.2

    $ gcc 1.c && ./a.out
    42
    $ gcc -O3 1.c && ./a.out
    Segmentation fault

    j1392184, 28 Июля 2017

    Комментарии (16)
  5. Си / Говнокод #23213

    +1

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    #include <stdio.h>
    #include <stdlib.h>
    #include <inttypes.h>
    #include <string.h>
    #include <stddef.h>
    
    #define INITARR(arr,...)                                                                                      \
    do                                                                                                            \
    {                                                                                                             \
      typedef struct {typeof(*arr) __tmp_arr[sizeof( (typeof(*arr)[]){__VA_ARGS__} ) / sizeof(*arr)];} __tmp_str; \
      *((__tmp_str *)arr) = (__tmp_str){{__VA_ARGS__}};                                                           \
    } while(0)
    
    
    
    int main(void)
    {
      uint8_t *test;
      test = malloc (sizeof (uint8_t[10]));
      INITARR(test,1,2,3,4,5,6,7,8,9,10);  
      for (size_t i = 0; i < 10; i++)
      {
        printf("%" PRIu8 ", ", test[i]);
      }
      return 0;
    }

    Для удобной инициализации массивов в хипе

    j123123, 23 Июля 2017

    Комментарии (6)
  6. Си / Говнокод #23211

    −1

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    Сишечные строки для printf-подобной параши из прошивки ESP8266 (для веб-сервера):
    ....
    method="POST">Login: <INPUT size=10 NAME='login' value="%s"> Password: <INPUT size=10 NAME='pass' value="%s"></td></tr><br><INPUT TYPE='checkbox' NAME='fls'%s> Full Security.
    <input type="hidden" name="st" value=5><br>%s
    <hr><b>Config module:</b><br><div class="spH2"></div><form method="GET">Host name: <INPUT size=12 NAME='hn' value="%s">
    <input type="hidden" name="st" value=7><br>%s
    <hr><b>WiFi options:</b><br><div class="spH2"></div><form method="GET"><input type="radio" name="sm" value="0" %s>Station mode.<input type="radio" name="sm" value="7" %s>AP mode.<br>AP name: <input size=20 name="stname" value="%s"> <br>AP pass: <input size=20 type='password' name="stpass" value="%s"><br>
    <!DOCTYPE html><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>%s</title><meta http-equiv="REFRESH" content="60"><meta name="viewport" content="width=480" /><meta name="mobile-web-app-capable" content="yes" /><link rel="stylesheet" href="main.css"></head><body><br><div style="text-align: center"><div style="display: inline-block"><div class="name fll">%s<div class="www">MaksMS <a href="http://wifi-iot.com" target="_blank">wifi-iot.com</a><br>

    ... и никакого пхп
    http://wifi-iot.com/ вот тут можно генерировать такие говнопрошивки

    j123123, 23 Июля 2017

    Комментарии (4)
  7. Си / Говнокод #23209

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    #include <stdio.h>
    #include <sys/types.h>
    #include <sys/socket.h>
    #include <errno.h>
    #include <stdlib.h>
    
    int main(int argc, char *argv[])
    {
    	int sock = socket(AF_LOCAL, SOCK_STREAM, 0);
    	if(sock == -1)
    	   printf("Error\n");
    	
    	int enable=1;
    	int ret = setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (const char*)&enable, sizeof(enable));
    	if(ret==-1)
    	    perror("Error");
        else
            printf("Sucess\n");
    	
    	int optval;
    	int optlen;
    	ret = getsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &optval, &optlen);
    	if(ret==0)
    	{
           if(optval != 0)
               printf("SO_REUSEADDR enabled\n");
           else
               printf("SO_REUSEADDR disabled\n");
        }
    	else
    	{
    		if(errno==EBADF)
                printf("The argument sockfd is not a valid file descriptor.\n");
    		else if(errno==EFAULT)
    		    printf("The address pointed to by optval is not in a valid part of.the process address space.  For getsockopt(), this error may also be returned if optlen is not in a valid part of the process address space.\n");
    		else if(errno==EINVAL)
    		    printf("optlen invalid in setsockopt().  In some cases this error.can also occur for an invalid value in optval (e.g., for the IP_ADD_MEMBERSHIP option described in ip(7)).\n");
    		else if(errno==ENOPROTOOPT)
    		    printf("The option is unknown at the level indicated.\n");
    		else if(errno==ENOTSOCK)
    		    printf("The file descriptor sockfd does not refer to a socket.\n");
    	}
    	
    	char *name;
    	name="ccmni0";
    	if( (setsockopt(sock, SOL_SOCKET, SO_BINDTODEVICE, name, 6)) < 0)
    	   printf("SO_BINDTODEVICE error\n");
    	char *arr[7];
    	int ss = 7;
    	ret = getsockopt(sock, SOL_SOCKET, SO_BINDTODEVICE, &arr, &ss);
    	if(ret==0)
    	{
    		printf("SO_BINDTODEVICE: %s\n", arr);
    	}
    	else
    	{
    		if(errno==EBADF)
                printf("The argument sockfd is not a valid file descriptor.\n");
    		else if(errno==EFAULT)
    		    printf("The address pointed to by optval is not in a valid part of.the process address space.  For getsockopt(), this error may also be returned if optlen is not in a valid part of the process address space.\n");
    		else if(errno==EINVAL)
    		    printf("optlen invalid in setsockopt().  In some cases this error.can also occur for an invalid value in optval (e.g., for the IP_ADD_MEMBERSHIP option described in ip(7)).\n");
    		else if(errno==ENOPROTOOPT)
    		    printf("The option is unknown at the level indicated.\n");
    		else if(errno==ENOTSOCK)
    		    printf("The file descriptor sockfd does not refer to a socket.\n");
    	}
    }

    Посру малёха!

    botC, 21 Июля 2017

    Комментарии (0)
  8. Си / Говнокод #23204

    +1

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    #include <stdio.h>
    
    int main()
    {
    	int num=10;
    	for(;;)
    	{
    		double num=15;
    		printf("%g", num);
    		for(;;)
    		{
    			char num = 'A'+10;
    			printf("%c\n", num);
    			for(;;)
    			{
    				float num = 4.686;
    				printf("%5.3f\n", num);
    				break;
    			}
    			break;
    		}
    		break;
        }
    }

    Говно, а точнее понос

    ProgRamistYshka, 20 Июля 2017

    Комментарии (1)
  9. Си / Говнокод #23203

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    #include <stdio.h>
    #include <errno.h>
    #include <unistd.h>
    int main()
    {
      FILE *popen_result;
      char buff[512];
      char *cmd = "lss";
      int temperr = dup(2);               // copy where stderr is at the moment
      freopen("/dev/null", "w", stderr);  // trash stderr reports from popen shell
      popen_result = popen(cmd, "r");
      if( popen_result==NULL )
          printf("Error!\n");
      stderr = fdopen(temperr,"w");       // get back stderr
      perror(cmd);
      if ( feof(popen_result) )
        printf("Already at EOF!\n");
      if ( ferror(popen_result) )
        printf("Already at error!\n");
      int err=1;
      while(fgets(buff, sizeof(buff), popen_result)!=NULL){
            printf(">>> %s", buff);
            err=0;
      }
      if( err==1 )
          printf("Error! Command %s not found\n", cmd);
      if( feof(popen_result) && err==0)
          printf("EOF cmd\n");
      pclose(popen_result);
    }

    Хакерские манипуляции часто бывают бесполезны

    ProgRamistYshka, 20 Июля 2017

    Комментарии (0)
  10. Си / Говнокод #23202

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    #include <stdio.h>
    
    int one(int num)
    {
    	int c=200;
    	for(int i=0;i<50000;i++)
    	{
    		num=c*num;
    		num-=c+c;
    	}
    	return num;
    }
    
    int two(int num)
    {
    	int d=456;
    	for(;d<7899;d++)
    	{
    		num=d*num+num;
    		num-=d*d;
    	}
    	return d;
    }
    
    int main(int atgc, char *argv[])
    {
    	unsigned i=one(777);
    	unsigned a=two(999);
    	printf("Тест ЦП завершён: %d\n", -i+a);
    }

    Попытка сделать тест цп

    ProgRamistYshka, 20 Июля 2017

    Комментарии (0)