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

    +128

    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
    #ifndef __KERNEL__
    /* Multicast groups - backwards compatiblility for userspace */
    #define SELNL_GRP_NONE		0x00000000
    #define SELNL_GRP_AVC		0x00000001	/* AVC notifications */
    #define SELNL_GRP_ALL		0xffffffff
    #endif
    
    enum selinux_nlgroups {
    	SELNLGRP_NONE,
    #define SELNLGRP_NONE	SELNLGRP_NONE
    	SELNLGRP_AVC,
    #define SELNLGRP_AVC	SELNLGRP_AVC
    	__SELNLGRP_MAX
    };
    #define SELNLGRP_MAX	(__SELNLGRP_MAX - 1)

    Linux 3.3.0
    include/linux/selinux_netlink.h

    myaut, 15 Апреля 2012

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

    +133

    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
    #include <stdio.h>
    
    float abs(float a) { return a > 0 ? a : -a; }
    
    int main() {
        float x, e, step = 1, summ = step;
        int i = 0;
        
        scanf("%f, %f", (printf("x, e: "), &x), &e);
        
        do summ += (abs(step *= x / ++i) > e) ? step : 0; while (abs(step) > e);
        
        printf("summ = %f\n", summ);
        
        return 0;
    }

    вычисление суммы ряда (1 + x/1! + x^2/2! + ... + x^n/n!), с заданной точностью

    igoreknog, 14 Апреля 2012

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

    +140

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    long long int temp;
    		temp=a-b;
    		if (temp<0) temp=temp*(-1);
    .....
    r = b*(2^g);

    Из работ студентов.
    Первый фрагмент - взятие по модулю.
    Второй - вызвал вопрос "почему неправильно работает возведение в степень?".

    startrack, 11 Апреля 2012

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

    +98

    1. 1
    enum { SIZEOF_INT_AS_STR = sizeof("4294967295,")-1 };

    Что это? :-O

    anmartex, 06 Апреля 2012

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

    +137

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    int str_fpos(char * in_str,char chr1) 
    {
       int i=0;
       char * pch = strchr(in_str,chr1);
       while (pch != NULL)
       {
          i = pch-in_str;//+1;
          break;
       }
       return i;
    }

    if-ом пользуются только трусы!!!

    anmartex, 06 Апреля 2012

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

    +130

    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
    int i,j;
    	char alph[]="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    	//Подстановка по таблице 1
    	int S_there[26][8]={{1,0,0,1,1,0,0,1},{1,0,0,0,1,0,0,0},{1,0,1,0,1,0,1,0},{0,0,1,1,0,0,1,1},{1,1,1,0,0,0,0,1},
    {1,0,0,0,0,1,1,1},{1,1,1,1,1,1,1,1},{1,1,0,1,0,0,1,0},{0,1,1,1,1,0,0,0},{1,1,0,0,0,0,1,1},{1,0,1,0,0,1,0,1},{0,1,0,0,1,0,1,1},
    {0,0,0,1,1,1,1,0},{0,1,0,1,0,1,0,1},{1,1,0,0,1,1,0,0},{0,0,0,1,0,0,0,1},{1,1,0,1,1,1,0,1},{1,0,1,1,0,1,0,0},{0,0,1,0,1,1,0,1},
    {0,0,0,0,0,0,0,0},{0,1,1,0,0,1,1,0},{0,1,0,0,0,1,0,0},{1,1,1,1,0,0,0,0},{0,0,1,1,1,1,0,0},{0,1,1,0,1,0,0,1},{0,0,1,0,0,0,1,0}};
    	
    	char str[]="THIISATESTFILEFORCHECKINGCYPHERMODULE";
    	int len=strlen(str);
        	int num[len];//массив с порядковыми номерами
    	int vector[len][8];//массив с ОТ, переведённым в двоичные вектора длины 8
    
    	for (i=0; i< len; i++)//Присваиваем каждой букве порядковый номер (а=0,b=1 и т.д.)
    	{
    		num[i]=((strchr(alph, str[i])-alph)% 26 + 0x01);
    		num[i]--;
    	}
    
    	for (i=0; i<len; i++)//Меняем букву на двоичный вектор длины 8 согласно порядковому номеру
    	{
    		int number=num[i];//счётчик текста
    		for (j=0; j<8; j++)
    		{
    			vector[i][j]=S_there[number][j];
    		}
    	}
    	for (i=0; i<len; i++)//Вывод на экран ОТ
    	{
    		for (j=0; j<8; j++)
    		{
    			printf("%u",vector[i][j]);
    		}
    		printf(" %c\n",str[i]);
    	}

    Нашёл в своей очень старой лабе...Нужно было буквы на входе преобразовать в двоичные вектора (например, а=10011001, b=10001000 и т.д.) ну и дальше ковыряться с этими векторами...почему я категорически не захотел тогда использовать case - хз :)))

    Pecho, 29 Марта 2012

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

    +134

    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
    /* страйкер, почини trim */
      while (1)
        {
          file_ptr start;
          int i;
          long c;
    
          /* See if the next `string_min' chars are all graphic chars.  */
        tryline:
          if (stop_point && address >= stop_point)
    	break;
          start = address;
          for (i = 0; i < string_min; i++)
    	{
    	  c = get_char (stream, &address, &magiccount, &magic);
    	  if (c == EOF)
    	    {
    	      free (buf);
    	      return;
    	    }
    	  if (! STRING_ISGRAPHIC (c))
    	    /* Found a non-graphic.  Try again starting with next char.  */
    	    goto tryline;
    	  buf[i] = c;
    	}

    Раз уж вспоминаем дрѣвния говны

    Written by Richard Stallman <[email protected]>
    and David MacKenzie <[email protected]>.

    bugmenot, 26 Марта 2012

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

    +134

    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
    зависающие маллок )))
    
    void * __cdecl malloc(size_t size)
    {
    	// No fail malloc!
    	void *pMem;
    	do {
    		pMem=HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,size);
    		if(pMem==NULL) Sleep(2000);
    	} while(pMem==NULL);
    
    	return pMem;
    }
    
    void * __cdecl operator new( unsigned int cb )
    {
    	// No fail new!
    	void *pMem;
    	do {
    		pMem=HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,cb);
    		if(pMem==NULL) Sleep(2000);
    	} while(pMem==NULL);
    
    	return pMem;
    }
    
    
    что хотел аффтар ? !!! аццкий сотона
    
    int GetCfgBool(char *cfgstr,const char *key)
    {
    	return GetCfgNum(cfgstr,key)?TRUE:FALSE;
    }
    
    аффтар застрелись !!!
    
    char *GetCfgStr(char *cfgstr,const char *key)
    {
    	char *str=cfgstr;
    	
    	// Skip past name of options list
    	while(*str!='\0') str++;
    	str++;
    	// Walk through options
    	while(*str!='\0') {
    		int nLen;
    		if(*str=='B') {
    			nLen=1;
    			str+=2;
    			if(strncmp(str,key,strlen(key))==0) break;
    		} else if(*str=='S') {
    			str+=2;
    			nLen=atoi(str);
    			while(*str!=']') str++;
    			str+=2;
    			if(strncmp(str,key,strlen(key))==0) break;
    		} else if(*str=='N') {
    			str+=2;
    			char *pb;
    			pb=str;
    			while(*str!=',') str++;
    			nLen=(DWORD)str-(DWORD)pb;
    			str++;
    			pb=str;
    			while(*str!=']') str++;
    			int nLen2=(DWORD)str-(DWORD)pb;
    			if(nLen2>nLen) nLen=nLen2;
    			str+=2;
    			if(strncmp(str,key,strlen(key))==0) break;
    		}
    		while(*str!='=') str++;
    		str++;
    		str+=(nLen+1);
    	}
    	if(*str!='\0') {
    		while(*str!='=') str++;
    		return str+1;
    	}
    	
    	return NULL;
    }
    
    
    исходники BO2K гениально !!!)) 
    и как не стыдно ЭТО распространять 
    http://www.bo2k.com/

    63F45EF45RB65R6VR, 26 Марта 2012

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

    +133

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    // for cdio:
    #include <cdio.h>
    #include <cdio_unconfig.h> # remove *all* symbols libcdio defines
    
    // Add back in the ones you want your program
    #include <config.h>

    But now what about the problem that there are common preprocessor symbols in config_cdio.h that an application may want to define in a different manner, like PACKAGE_NAME?
    For this, there is yet another header, <cdio/cdio_unconfig.h>.

    rat4, 20 Марта 2012

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

    +127

    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
    typedef struct _xjmp_stru {
        unsigned long Ebp;
        unsigned long Ebx;
        unsigned long Edi;
        unsigned long Esi;
        unsigned long Esp;
        unsigned long Eip;
    } xjmp_stru;
    
    typedef int xjmp_buf[6];
    
    __declspec(naked)
    int __cdecl xsetjmp(xjmp_buf)
    {
    	__asm
    	{
    		mov     edx, [esp+4]
    		mov     [edx], ebp
    		mov     [edx+4], ebx
    		mov     [edx+8], edi
    		mov     [edx+12], esi
    		mov     [edx+16], esp
    		mov     eax, [esp]
    		mov     [edx+20], eax
    		xor     eax, eax
    		ret
    	}
    } 
    
    
    __declspec(naked, noreturn)
    void __cdecl xlongjmp(xjmp_buf, int)
    {
    	__asm
    	{
    		mov     edx, [esp+4]
    		mov     ebp, [edx]
    		mov     ebx, [edx+4]
    		mov     edi, [edx+8]
    		mov     esi, [edx+12]
    		mov     eax, [esp+8]
    		test    eax, eax
    		jne     __
    		inc     eax
    __:      
    		mov     esp, [edx+16]
    		add     esp, 4
    		mov     edx, [edx+20]
    		jmp     edx
    	}
    } 
    
    int dummy(xjmp_buf jbuf)
    {
    	volatile int jk = 8;
    	if (jk)
    		xlongjmp(jbuf, 2);
    	else
    		return 7;
    }
    
    int main()
    {
    	xjmp_buf jbuf;
    	if (xsetjmp(jbuf))
    	{
    		puts("excpt");
    		return -1;
    	}
    	dummy(jbuf);
    	puts("great work");
    	return 0;
    }

    экая хренотень

    63F45EF45RB65R6VR, 13 Марта 2012

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