fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. //宣言
  5. int GetBoundary( char **reBou );
  6. int GetEXTinHeader( char **reEXT );
  7.  
  8. //メイン関数
  9. int main(void){
  10. char *pBoundary = NULL;//バウンダリ文字列の先頭のポインタ
  11. int boundaryNum = 0;//バウンダリの文字数
  12. char *pEXT = NULL;
  13.  
  14. boundaryNum = GetBoundary( &pBoundary );
  15. if(boundaryNum == -1) return 0;
  16.  
  17. if(GetEXTinHeader(&pEXT) == -1) return 0;
  18.  
  19. printf("%s",pEXT);
  20.  
  21. return 0;
  22. }
  23.  
  24.  
  25. //引数(バウンダリー文字列を返すポインタ)
  26. //返り値(正常:格納した文字数、不正:-1)
  27. int GetBoundary( char **reBou )
  28. {
  29. char boundary[70] = {};
  30. int i = 0, tmp = 0;
  31.  
  32. while(i<70){
  33. tmp = getchar();
  34. if( tmp <= 0 ) return -1;
  35. if( tmp == '\n' ){
  36. *reBou = (char*)malloc(sizeof(char)*(i+1));//reBouにバウンダリの文字数分メモリを確保
  37. strncpy(*reBou,boundary,i);//バウンダリ文字列をコピー
  38. *(*reBou + i) = '\0';//最後にヌル文字を入れる
  39.  
  40. return i;
  41. }
  42. boundary[i] = tmp;
  43. i++;
  44. }
  45. return -1;
  46. }
  47.  
  48.  
  49. //引数(拡張子を返すポインタ)
  50. //返り値(正常:0、不正:-1)
  51. int GetEXTinHeader( char **reEXT )
  52. {
  53. char ext[3] = {};
  54. char strTMP[11] = "filename=\"";
  55. int j=0, tmp=0;
  56.  
  57. for(j=0;j!=46;j++){
  58. if(getchar()<=0) return -1;
  59. }
  60.  
  61. for(j=0;j!=10;j++){
  62. if(strTMP[j] != getchar()) return -1;
  63. }
  64.  
  65. while(1){
  66. tmp = getchar();
  67. if(tmp <= 0 || tmp == '\n') return -1;
  68. if(tmp == '.'){
  69. for(j=0;j!=3;j++){
  70. tmp = getchar();
  71. if(tmp <= 0 || tmp == '\n') return -1;
  72. ext[j] = tmp;
  73. }
  74. if(getchar() == '\"'){
  75. *reEXT = (char*)malloc(sizeof(char)*4);
  76. strncpy(*reEXT,ext,3);
  77. *(*reEXT + 4) = '\0';
  78. return 0;
  79. }
  80. }
  81. }
  82. }
Success #stdin #stdout 0s 2428KB
stdin
------WebKitFormBoundaryNDBtovEU2Qd7ntvC
Content-Disposition: form-data; name="file1"; filename="てすとん.jpg"
Content-Type: application/octet-stream

this is file
------WebKitFormBoundaryNDBtovEU2Qd7ntvC
Content-Disposition: form-data; name="file2"; filename=""
Content-Type: application/octet-stream


------WebKitFormBoundaryNDBtovEU2Qd7ntvC
Content-Disposition: form-data; name="file3"; filename=""
Content-Type: application/octet-stream


------WebKitFormBoundaryNDBtovEU2Qd7ntvC
Content-Disposition: form-data; name="file4"; filename=""
Content-Type: application/octet-stream


------WebKitFormBoundaryNDBtovEU2Qd7ntvC
Content-Disposition: form-data; name="file5"; filename=""
Content-Type: application/octet-stream


------WebKitFormBoundaryNDBtovEU2Qd7ntvC
stdout
jpg