get 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. #RETR $FISH_FILENAME $FISH_START_OFFSET
  2. LC_TIME=C
  3. export LC_TIME
  4. fish_get_perl ()
  5. {
  6. FILENAME=$1
  7. OFFSET=$2
  8. perl -e '
  9. use strict;
  10. use POSIX;
  11. use Fcntl;
  12. my $filename = $ARGV[0];
  13. my $pos = $ARGV[1];
  14. my $content;
  15. my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks) = lstat("$filename");
  16. my $n;
  17. if (open IFILE,$filename) {
  18. if ($size<$pos) {
  19. printf("0\n");
  20. } else {
  21. $size-=$pos;
  22. printf("$size\n");
  23. }
  24. printf("### 100\n");
  25. seek (IFILE, $pos, 0);
  26. while ($n = read(IFILE,$content,$blocks)!= 0) {
  27. print $content;
  28. }
  29. close IFILE;
  30. printf("### 200\n");
  31. } else {
  32. printf("### 500\n");
  33. }
  34. exit 0
  35. ' "${FILENAME}" $OFFSET
  36. }
  37. fish_get_tail ()
  38. {
  39. FILENAME=$1
  40. OFFSET=$2
  41. LC_TIME=C
  42. export LC_TIME
  43. if dd if="${FILENAME}" of=/dev/null bs=1 count=1 2>/dev/null ; then
  44. file_size=`ls -ln "${FILENAME}" 2>/dev/null | (
  45. read p l u g s r
  46. echo $s
  47. )`
  48. if [ $OFFSET -gt 0 ]; then
  49. file_size=`expr $file_size - $OFFSET`
  50. OFFSET=`expr $OFFSET + 1`
  51. fi
  52. if [ $file_size -gt 0 ]; then
  53. echo $file_size
  54. else
  55. echo 0
  56. fi
  57. echo "### 100"
  58. if [ $OFFSET -gt 0 ]; then
  59. tail -c +${OFFSET} "${FILENAME}"
  60. else
  61. cat "${FILENAME}"
  62. fi
  63. echo "### 200"
  64. else
  65. echo "### 500"
  66. fi
  67. }
  68. fish_get_dd ()
  69. {
  70. FILENAME=$1
  71. OFFSET=$2
  72. LC_TIME=C
  73. export LC_TIME
  74. if dd if="${FILENAME}" of=/dev/null bs=1 count=1 2>/dev/null ; then
  75. file_size=`ls -ln "${FILENAME}" 2>/dev/null | (
  76. read p l u g s r
  77. echo $s
  78. )`
  79. file_size=`expr $file_size - $OFFSET`
  80. if [ $file_size -gt 0 ]; then
  81. echo $file_size
  82. else
  83. echo 0
  84. fi
  85. echo "### 100"
  86. if [ $OFFSET -gt 0 ]; then
  87. dd skip=$OFFSET ibs=1 if="${FILENAME}" 2>/dev/null
  88. else
  89. cat "${FILENAME}"
  90. fi
  91. echo "### 200"
  92. else
  93. echo "### 500"
  94. fi
  95. }
  96. if [ -n "${FISH_HAVE_PERL}" ]; then
  97. fish_get_perl "/${FISH_FILENAME}" ${FISH_START_OFFSET}
  98. elif [ -n "${FISH_HAVE_TAIL}" ]; then
  99. fish_get_tail "/${FISH_FILENAME}" ${FISH_START_OFFSET}
  100. else
  101. fish_get_dd "/${FISH_FILENAME}" ${FISH_START_OFFSET}
  102. fi