1. Лучший говнокод

    В номинации:
    За время:
  2. PHP / Говнокод #2798

    +162.2

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    $l = array('q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'z', 'x', 'c', 'v', 'b', 'n', 'm', '-', '.');
    $len = 9;
    for ($i = 0; $i < 100; $i++) //цикл для проверки=)
    {
        $login = '';
        while (strlen($login) < $len) {
            $current = $l[mt_rand(0, (((strlen($login) + 1 == $len) || (strlen($login) == 0)) ? count($l) - 3 : count($l) - 1))]; //мама ради миня абратна
            $login. = ((substr($login, strlen($login) - 1, 1)) == $current) ? '' : $current;
        }
    
        echo $login."<br>";
    }

    наверно самый извращенный код для генереции случайних строк который я когда либо писал=)
    примерно такие требования
    в начале и в конце как точки, так и тире быть тоже не должно
    Т.е другими словами, должен начинаться буквой и заканчиваться буквой
    не иметь двух тире и двухточие подряд

    nur, 15 Марта 2010

    Комментарии (17)
  3. JavaScript / Говнокод #2796

    +161

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    function isValidEmail(address) {
        if (address.indexOf('@') < 1) return false;
        var name = address.substring(0, address.indexOf('@'));
        var domain = address.substring(address.indexOf('@') + 1);
        if (name.indexOf('(') != -1 || name.indexOf(')') != -1 || name.indexOf('<') != -1 || name.indexOf('>') != -1 || name.indexOf(',') != -1 || name.indexOf(';') != -1 || name.indexOf(':') != -1 || name.indexOf('\\') != -1 || name.indexOf('"') != -1 || name.indexOf('[') != -1 || name.indexOf(']') != -1 || name.indexOf(' ') != -1) return false;
        if (domain.indexOf('(') != -1 || domain.indexOf(')') != -1 || domain.indexOf('<') != -1 || domain.indexOf('>') != -1 || domain.indexOf(',') != -1 || domain.indexOf(';') != -1 || domain.indexOf(':') != -1 || domain.indexOf('\\') != -1 || domain.indexOf('"') != -1 || domain.indexOf('[') != -1 || domain.indexOf(']') != -1 || domain.indexOf(' ') != -1) return false;
        return true;
    }

    проверка email на валидность по индусски

    avm, 15 Марта 2010

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

    +94.2

    1. 001
    2. 002
    3. 003
    4. 004
    5. 005
    6. 006
    7. 007
    8. 008
    9. 009
    10. 010
    11. 011
    12. 012
    13. 013
    14. 014
    15. 015
    16. 016
    17. 017
    18. 018
    19. 019
    20. 020
    21. 021
    22. 022
    23. 023
    24. 024
    25. 025
    26. 026
    27. 027
    28. 028
    29. 029
    30. 030
    31. 031
    32. 032
    33. 033
    34. 034
    35. 035
    36. 036
    37. 037
    38. 038
    39. 039
    40. 040
    41. 041
    42. 042
    43. 043
    44. 044
    45. 045
    46. 046
    47. 047
    48. 048
    49. 049
    50. 050
    51. 051
    52. 052
    53. 053
    54. 054
    55. 055
    56. 056
    57. 057
    58. 058
    59. 059
    60. 060
    61. 061
    62. 062
    63. 063
    64. 064
    65. 065
    66. 066
    67. 067
    68. 068
    69. 069
    70. 070
    71. 071
    72. 072
    73. 073
    74. 074
    75. 075
    76. 076
    77. 077
    78. 078
    79. 079
    80. 080
    81. 081
    82. 082
    83. 083
    84. 084
    85. 085
    86. 086
    87. 087
    88. 088
    89. 089
    90. 090
    91. 091
    92. 092
    93. 093
    94. 094
    95. 095
    96. 096
    97. 097
    98. 098
    99. 099
    100. 100
    procedure TNamePlay.OKBtnClick(Sender: TObject);
    var
     reg:treginifile;
     a,s,d,f,g,h,j,k,l,z,x:integer;
    begin
    if setp.CheckBox1.Checked =true then
    playsound('Music\xxx.WAV',0,snd_async);
    
     if vopros.Easy.Checked=false then
      och.Caption:=inttostr(strtoint(och.caption)+50);
     with gamers do begin
       Reg := TReginifile.Create;
       Reg.RootKey := HKEY_LOCAL_MACHINE;
       with reg do begin
        o1.caption:=readstring('Software\xxx\Gamers\Result','First','');
        o2.caption:=readstring('Software\xxx\Gamers\Result','Two','');
        o3.caption:=readstring('Software\xxx\Gamers\Result','Three','');
        o4.caption:=readstring('Software\xxx\Gamers\Result','Four','');
        o5.caption:=readstring('Software\xxx\Gamers\Result','Five','');
        o6.caption:=readstring('Software\xxx\Gamers\Result','Six','');
        o7.caption:=readstring('Software\xxx\Gamers\Result','Seven','');
        o8.caption:=readstring('Software\xxx\Gamers\Result','Eight','');
        o9.caption:=readstring('Software\xxx\Gamers\Result','Nine','');
        o10.caption:=readstring('Software\xxx\Gamers\Result','Ten','');
        g1.caption:=readstring('Software\xxx\Gamers','First','');
        g2.caption:=readstring('Software\xxx\Gamers','Two','');
        g3.caption:=readstring('Software\xxx\Gamers','Three','');
        g4.caption:=readstring('Software\xxx\Gamers','Four','');
        g5.caption:=readstring('Software\xxx\Gamers','Five','');
        g6.caption:=readstring('Software\xxx\Gamers','Six','');
        g7.caption:=readstring('Software\xxx\Gamers','Seven','');
        g8.caption:=readstring('Software\xxx\Gamers','Eight','');
        g9.caption:=readstring('Software\xxx\Gamers','Nine','');
        g10.caption:=readstring('Software\xxx\Gamers','Ten','');
       end;
     end;
     if password.Text='' then
      raise erangeerror.Create('Вы не ввели имени')
     else begin
      with gamers do begin
       a:=strtoint(o1.caption);
       s:=strtoint(o2.caption);
       d:=strtoint(o3.caption);
       f:=strtoint(o4.caption);
       g:=strtoint(o5.caption);
       h:=strtoint(o6.caption);
       j:=strtoint(o7.caption);
       k:=strtoint(o8.caption);
       l:=strtoint(o9.caption);
       z:=strtoint(o10.caption);
       x:=strtoint(nameplay.och.caption);
       if x>a then begin
        g10.Caption:=g9.Caption;
        o10.Caption:=o9.caption;
        g9.Caption:=g8.Caption;
        o9.Caption:=o8.caption;
        g8.Caption:=g7.Caption;
        o8.Caption:=o7.caption;
        g7.Caption:=g6.Caption;
        o7.Caption:=o6.caption;
        g6.Caption:=g5.Caption;
        o6.Caption:=o5.caption;
        g5.Caption:=g4.Caption;
        o5.Caption:=o4.caption;
        g4.Caption:=g3.Caption;
        o4.Caption:=o3.caption;
        g3.Caption:=g2.Caption;
        o3.Caption:=o2.caption;
        g2.Caption:=g1.Caption;
        o2.Caption:=o1.caption;
        g1.Caption:=nameplay.Password.Text;
        o1.Caption:=nameplay.och.Caption;
       end else if x=a then begin
        g1.Caption:=nameplay.Password.Text;
        o1.Caption:=nameplay.och.Caption;
       end else if x<a then begin
        if x>s then begin
         g10.Caption:=g9.Caption;
         o10.Caption:=o9.caption;
         g9.Caption:=g8.Caption;
         o9.Caption:=o8.caption;
         g8.Caption:=g7.Caption;
         o8.Caption:=o7.caption;
         g7.Caption:=g6.Caption;
         o7.Caption:=o6.caption;
         g6.Caption:=g5.Caption;
         o6.Caption:=o5.caption;
         g5.Caption:=g4.Caption;
         o5.Caption:=o4.caption;
         g4.Caption:=g3.Caption;
         o4.Caption:=o3.caption;
         g3.Caption:=g2.Caption;
         o3.Caption:=o2.caption;
         g2.Caption:=nameplay.Password.Text;
         o2.Caption:=nameplay.och.Caption;
        end else if x=s then begin
         g2.Caption:=nameplay.Password.Text;
         o2.Caption:=nameplay.och.Caption;
        end else if x<s then begin
    ...

    Ололо, феерический говнокод! LOL

    ancestor, 15 Марта 2010

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

    +138.9

    1. 1
    2. 2
    3. 3
    4. 4
    res =  Wlxtbl.WlxLoggedOutSAS(pWlxContext,dwSasType,pAuthenticationId,pLogonSid,pdwOptions,phToken,pNprNotifyInfo,pProfile);
    switch(res) {
    	case WLX_SAS_ACTION_LOGON:
    		if(res == WLX_SAS_ACTION_LOGON) {

    Пишу свою gina.dll, только что заметил вот это...

    zitzy, 12 Марта 2010

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

    +106.7

    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
    //Разбор принятых данных
    
      //===========================================================================
      //IP-адрес сервера
      //===========================================================================
       for(i=0;i<16;i++)
    	 {
    	  if(CtrlData[i] == ',')
    		break;
    	  else
    		buf[i] = CtrlData[i];
    	 }
    
       //разбираем первый байт адреса
       if(buf[1]=='.')      //вариант 1.
    	 {
    	  ip_buf[0] = ' ';
    	  ip_buf[1] = ' ';
    	  ip_buf[2] = buf[0];
    	  ip_buf[3] = buf[1];
    	  ip_ptr = 2;
    	 }
       else if(buf[2]=='.') //вариант 11.
    	 {
    	  ip_buf[0] = ' ';
    	  ip_buf[1] = buf[0];
    	  ip_buf[2] = buf[1];
    	  ip_buf[3] = buf[2];
    	  ip_ptr = 3;
    	 }
       else if(buf[3]=='.') //вариант 111.
    	 {
    	  for(i=0;i<4;i++)
    		ip_buf[i] = buf[i];
    	  ip_ptr = 4;
    	 }
       else
    	 {
    	  MessageBox(0, "Память устройства или файл содержит неверные данные","Ошибка", MB_ICONERROR|MB_TOPMOST|MB_OK|MB_TASKMODAL);
    	  return 1;
    	 }
    
       //разбираем второй байт адреса
       if(buf[ip_ptr+1]=='.')      //вариант 1.
    	 {
    	  ip_buf[4] = ' ';
    	  ip_buf[5] = ' ';
    	  ip_buf[6] = buf[ip_ptr];
    	  ip_buf[7] = buf[ip_ptr+1];
    	  ip_ptr += 2;
    	 }
       else if(buf[ip_ptr+2]=='.') //вариант 11.
    	 {
    	  ip_buf[4] = ' ';
    	  ip_buf[5] = buf[ip_ptr];
    	  ip_buf[6] = buf[ip_ptr+1];
    	  ip_buf[7] = buf[ip_ptr+2];
    	  ip_ptr += 3;
    	 }
       else if(buf[ip_ptr+3]=='.') //вариант 111.
    	 {
    	  ip_buf[4] = buf[ip_ptr];
    	  ip_buf[5] = buf[ip_ptr+1];
    	  ip_buf[6] = buf[ip_ptr+2];
    	  ip_buf[7] = buf[ip_ptr+3];
    	  ip_ptr += 4;
    	 }
       else
    	 {
    	  MessageBox(0, "Память устройства или файл содержит неверные данные","Ошибка", MB_ICONERROR|MB_TOPMOST|MB_OK|MB_TASKMODAL);
    	  return 1;
    	 }

    парсинг второй половины адреса сюда полностью не влез, но там ничего нового, я вас уверяю =)

    angry C nerd, 11 Марта 2010

    Комментарии (17)
  7. PHP / Говнокод #2732

    +147.2

    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
    if(!empty($_POST))
    {
    $url = trim($_POST['url']);
    if((substr($url, 0, 7)) == "http://") $url = str_replace('http://','',$url);
    if((substr($url, 0, 4)) == "www.") $url = str_replace('www.','',$url);
    if(strpos($url,'/')>0) list($url) = explode('/',$url);
    
    $domain = array(
    array("ac","whois.nic.ac","No match"),
    array("ac.cn","whois.cnnic.net.cn","no matching record"),
    array("ac.jp","whois.nic.ad.jp","No match"),
    array("ac.uk","whois.ja.net","No such domain"),
    array("ad.jp","whois.nic.ad.jp","No match"),
    array("adm.br","whois.nic.br","No match"),
    array("adv.br","whois.nic.br","No match"),
    array("aero","whois.information.aero","is available"),
    array("ag","whois.nic.ag","Not found"),
    array("agr.br","whois.nic.br","No match"),
    array("ah.cn","whois.cnnic.net.cn","No entries found"),
    array("al","whois.ripe.net","No entries found"),
    array("am","whois.amnic.net","No match"),
    array("am.br","whois.nic.br","No match"),
    array("arq.br","whois.nic.br","No match"),
    array("at","whois.nic.at","nothing found"),
    array("au","whois.aunic.net","No Data Found"),
    array("art.br","whois.nic.br","No match"),
    array("as","whois.nic.as","Domain Not Found"),
    array("asn.au","whois.aunic.net","No Data Found"),
    array("ato.br","whois.nic.br","No match"),
    array("av.tr","whois.nic.tr","Not found in database"),
    array("az","whois.ripe.net","no entries found"),
    array("ba","whois.ripe.net","No match for"),
    array("be","whois.geektools.com","No such domain"),
    array("bg","whois.digsys.bg","does not exist"),
    array("bio.br","whois.nic.br","No match"),
    array("biz","whois.biz","Not found"),
    array("biz.tr","whois.nic.tr","Not found in database"),
    array("bj.cn","whois.cnnic.net.cn","No entries found"),
    array("bel.tr","whois.nic.tr","Not found in database"),
    array("bmd.br","whois.nic.br","No match"),
    array("br","whois.registro.br","No match"),
    array("by","whois.ripe.net","no entries found"),
    array("ca","whois.cira.ca","Status: AVAIL"),
    array("cc","whois.nic.cc","No match"),
    array("cd","whois.cd","No match"),
    array("ch","whois.nic.ch","We do not have an entry"),
    array("cim.br","whois.nic.br","No match"),
    array("ck","whois.ck-nic.org.ck","No entries found"),
    array("cl","whois.nic.cl","no existe"),
    array("cn","whois.cnnic.net.cn","No entries found"),
    array("cng.br","whois.nic.br","No match"),
    // ...
    // Поскипана ещё куча таких же строк
    );
    
    $end = substr($url, strpos($url, ".") + 1);
    
    for($i = 0; $i < count($domain); $i++)
    {
    if($domain[$i][0] == $end)
    {
    
    $whois = $domain[$i][1];
    $no_found = $domain[$i][2];
    
    break;
    }
    }
    
    if(empty($whois)) exit("Нет данных по этому домену");
    
    @$fp = fsockopen($whois, 43) or exit ("Ошибка при обращении к серверу"); 
    
    fputs($fp, "$url\r\n");
    
    $answer = "";
    
    while(!feof($fp))
    {
    $answer .= "<tr><td>".fgets($fp,128)."</tr></td>";
    }
    
    fclose($fp);
    
    $answer = preg_replace("/".$no_found."/is", "Домен не найден.", $answer);
    
    echo "<h2>Информация о $url</h2>";
    echo "<table width=80%>";
    echo $answer;
    echo "</table>";
    }

    Кто первый разберется тот красавец)
    Отсюда: http://forum.wec.ru/index.php?showtopic=109033

    hdkeeper, 08 Марта 2010

    Комментарии (17)
  8. PHP / Говнокод #2725

    +147.8

    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
    <?php
    
    // *** Первая версия ***
    
    $numb = $_GET["n"]; // Получаем информацию
    $from = $_GET["f"];
    $to = $_GET["t"];
    
    if (!$numb or !$from or !$to) { // Проверяем есть ли информация, и полна ли она
    echo "<html><head><title>Перевод между сист. исчисл. 2<->36</title></head><body>"; // Выводим справку и ошибку
    echo "<center><u><i>Справка:</i></u> index.php?n=<b>число</b>&f=<b>исходная сист. исчисл.</b>&t=<b>конечная сист. исчисл.</b><hr></center>";
    echo "<center><b>ОШИБКА: Данные не обнаружены или неполные!</b><br>Возможно, что вы тут в первый раз...</center>";
    echo "</body></html>";
    } else {
    echo "<html><head><title>Перевод между сист. исчисл. 2<->36</title></head><body>"; // Выводим справку и результаты
    echo "<center><u><i>Справка:</i></u> index.php?n=<b>число</b>&f=<b>исходная сист. исчисл.</b>&t=<b>конечная сист. исчисл.</b><hr></center>";
    echo "<center>Исходное число: $numb<br>";
    echo "Начальная сист. исчисл.: $from<br>";
    echo "Конечная сист. исчисл.: $to<br>";
    echo "Результат: ";
    echo base_convert("$numb",$from,$to);
    echo "</center></body></html>";
    }
    
    ?>
    
    <?php
    
    // *** Вторая версия - форма ***
    
    echo "<html><head><title>Перевод между С.И.</title></head><body>"; // Выводим форму
    echo "<center><form method='post' action='new_e.php'>Исходное  число:<br><input type = 'text' name='n'><hr>";
    echo "Исходная С.И.:<br><input type='radio' name='f' value='2'>BIN (2)<br>";
    echo "<input type='radio' name='f' value='8'>OCT (8)<br>";
    echo "<input type='radio' name='f' value='10'>DEC (10)<br>";
    echo "<input type='radio' name='f' value='16'>HEX (16)<br>";
    echo "<hr>";
    echo "Конечная С.И.:<br><input type='radio' name='t' value='2'>BIN (2)<br>";
    echo "<input type='radio' name='t' value='8'>OCT (8)<br>";
    echo "<input type='radio' name='t' value='10'>DEC (10)<br>";
    echo "<input type='radio' name='t' value='16'>HEX (16)<br>";
    echo "<hr><input type='submit' value='Выполнить'></form></center>";
    echo "</center></body></html>";
    
    ?>
    
    <?php
    
    // *** Вторая версия - вычисления ***
    
    $numb = $_POST["n"]; // Получаем информацию
    $from = $_POST["f"];
    $to = $_POST["t"];
    
    echo "<html><head><title>Перевод между С.И.</title></head><body>"; // Выводим результаты
    echo "<center>Исх. число: $numb<br>";
    echo "Начальная С.И.: $from<br>";
    echo "Конечная С.И.: $to<br>";
    echo "Результат: ";
    echo base_convert("$numb",$from,$to);
    echo "<hr><center><a href='/new.php'>Назад</a></center>";
    echo "</center></body></html>";
    
    ?>

    Одно из первых моих творений, переводит числа в различные системы исчисления. Представлено две первые версии, одна получала через GET, а другая уже через POST. Первая "ручная" (то есть вбиваем в адрес данные ручками), а другая состояла из двух файлов (формы и собственно обработка и выполнение операции с полученных данных).

    Говнокод заключается в злоупотреблении ECHO (не думаю, что закинуть полученные данные в переменные тоже грех особый). Позже в третьей версии скрипта все было приведено в норму, и два файла были совмещены в один :)

    Мартин, 06 Марта 2010

    Комментарии (17)
  9. C++ / Говнокод #2709

    +73.5

    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
    //...                            
                                           }
    
                                        }
                                      }
                                      if(found) break;
                                    }
                                  }
                                  aStr=wcstok(NULL,m_cmdSEP);
                                }
                              }
                            }
                          }
                        }
                      }
                      else NoDeviceErrorActive(1);
                    }
                  }
                }
                else NoDeviceErrorActive(1);
              }
            }
          }
        }
      }
    //...

    Кусочек функции, сегодня наткнулся, сама функция занимает 540 строк, все методы класса -- 8000 =). И форматирование оригинальное -- не табами, а двумя пробелами =) . Мне нужно было просто посмотреть, как этот класс одну штуку делает, и я теперь сижу счастливый и думаю, как хорошо, что не мне этот код поддерживать =)

    ISith, 03 Марта 2010

    Комментарии (17)
  10. JavaScript / Говнокод #2704

    +166.8

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    function  trim(text) {
      if (text.length == 0) {
        return text;
      }
      if (text.charAt(0) == ' ') {
        return '';
      }
      if (text.charAt(text.length-1) == ' ') {
        text = text.substring(0, text.length-1);
      }
      return text;
    }

    суровый китайский trim...

    ClintEastwood, 02 Марта 2010

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

    +133.6

    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
    char *errdesc;
    
    [...]
    
                switch errno
                {
                    case EACCES: errdesc="For Unix domain sockets, which are identified by pathname: Write permission is denied on the socket file, or search permission is denied for one of the directories in the path prefix. (See also path_resolution(2).) " ;break;
                    case EPERM: errdesc="The user tried to connect to a broadcast address without having the socket broadcast flag enabled or the connection request failed because of a local firewall rule. ";break;
                    case EADDRINUSE: errdesc="Local address is already in use. ";break;
                    case EAFNOSUPPORT: errdesc="The passed address didn't have the correct address family in its sa_family field. ";break;
                    case EAGAIN: errdesc="No more free local ports or insufficient entries in the routing cache. For PF_INET see the net.ipv4.ip_local_port_range sysctl in ip(7) on how to increase the number of local ports. ";break;
                    case EALREADY: errdesc="The socket is non-blocking and a previous connection attempt has not yet been completed. ";break;
                    case EBADF: errdesc="The file descriptor is not a valid index in the descriptor table. ";break;
                    case ECONNREFUSED: errdesc="No one listening on the remote address. ";break;
                    case EFAULT: errdesc="The socket structure address is outside the user's address space. ";break;
                    case EINPROGRESS: errdesc="The socket is non-blocking and the connection cannot be completed immediately. It is possible to select(2) or poll(2) for completion by selecting the socket for writing. After select(2) indicates writability, use getsockopt(2) to read the SO_ERROR option at level SOL_SOCKET to determine whether connect() completed successfully (SO_ERROR is zero) or unsuccessfully (SO_ERROR is one of the usual error codes listed here, explaining the reason for the failure). ";break;
                    case EINTR: errdesc="The system call was interrupted by a signal that was caught. ";break;
                    case EISCONN: errdesc="The socket is already connected. ";break;
                    case ENETUNREACH: errdesc="Network is unreachable. ";break;
                    case ENOTSOCK: errdesc="The file descriptor is not associated with a socket. ";break;
                    case ETIMEDOUT: errdesc="Timeout while attempting connection. The server may be too busy to accept new connections. Note that for IP sockets the timeout may be very long when syncookies are enabled on the server.";break;
                    case EADDRNOTAVAIL: errdesc="EADDRNOTAVAIL";break;
                    case EPROTOTYPE: errdesc="EPROTOTYPE";break;
                    case EINVAL: errdesc="Invalid argument passed.";break;
                    case ENOMEM: errdesc="Could not allocate memory for recvmsg().";break;
                    case ENOTCONN: errdesc="The socket is associated with a connection-oriented protocol and has not been connected (see connect(2) and accept(2)).";break;
                    default: errdesc="Unknown error";break;
                }

    Мдя, просматривать код писанный мной же, когда я ещё только-только начинал писать на Си стыдновато. :)

    xaionaro, 28 Февраля 2010

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