006-busybox-1.23.0-vi.patch 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. --- busybox-1.23.0/editors/vi.c
  2. +++ busybox-1.23.0-vi/editors/vi.c
  3. @@ -542,9 +542,6 @@ static void cookmode(void); // return to
  4. static int mysleep(int);
  5. static int readit(void); // read (maybe cursor) key from stdin
  6. static int get_one_char(void); // read 1 char from stdin
  7. -#if !ENABLE_FEATURE_VI_READONLY
  8. -#define file_insert(fn, p, update_ro_status) file_insert(fn, p)
  9. -#endif
  10. // file_insert might reallocate text[]!
  11. static int file_insert(const char *, char *, int);
  12. static int file_write(char *, char *, char *);
  13. @@ -1325,7 +1322,7 @@ static void colon(char *buf)
  14. q = next_line(q);
  15. { // dance around potentially-reallocated text[]
  16. uintptr_t ofs = q - text;
  17. - size = file_insert(fn, q, /*update_ro:*/ 0);
  18. + size = file_insert(fn, q, 0);
  19. q = text + ofs;
  20. }
  21. if (size < 0)
  22. @@ -2905,7 +2902,7 @@ static char *get_input_line(const char *
  23. }
  24. // might reallocate text[]!
  25. -static int file_insert(const char *fn, char *p, int update_ro_status)
  26. +static int file_insert(const char *fn, char *p, int initial)
  27. {
  28. int cnt = -1;
  29. int fd, size;
  30. @@ -2918,7 +2915,8 @@ static int file_insert(const char *fn, c
  31. fd = open(fn, O_RDONLY);
  32. if (fd < 0) {
  33. - status_line_bold_errno(fn);
  34. + if (!initial)
  35. + status_line_bold_errno(fn);
  36. return cnt;
  37. }
  38. @@ -2946,7 +2944,7 @@ static int file_insert(const char *fn, c
  39. close(fd);
  40. #if ENABLE_FEATURE_VI_READONLY
  41. - if (update_ro_status
  42. + if (initial
  43. && ((access(fn, W_OK) < 0) ||
  44. /* root will always have access()
  45. * so we check fileperms too */