util-alone.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. /*
  2. * Author: 1998 Pavel Machek <pavel@ucw.cz>
  3. *
  4. * This is for making midnight commander's vfs stuff compile stand-alone
  5. *
  6. * Namespace pollution: horrible
  7. */
  8. #include <config.h>
  9. #include <stdio.h>
  10. #if defined(__os2__) /* OS/2 need io.h! .ado */
  11. # include <io.h>
  12. #endif
  13. #include <stdlib.h>
  14. #include <sys/types.h>
  15. #ifdef HAVE_UNISTD_H
  16. #include <unistd.h>
  17. #endif
  18. #include <fcntl.h>
  19. #include <signal.h> /* my_system */
  20. #include <limits.h> /* INT_MAX */
  21. #ifndef SCO_FLAVOR
  22. # include <sys/time.h> /* alex: sys/select.h defines struct timeval */
  23. #endif /* SCO_FLAVOR */
  24. #include <sys/param.h>
  25. #include <sys/types.h>
  26. #include <sys/stat.h>
  27. #include <stdarg.h>
  28. #include <errno.h> /* my_system */
  29. #ifdef SCO_FLAVOR
  30. # include <sys/timeb.h> /* alex: for struct timeb, used in time.h */
  31. #endif /* SCO_FLAVOR */
  32. #include <time.h>
  33. #ifndef OS2_NT
  34. # include <pwd.h>
  35. # include <grp.h>
  36. #endif
  37. #include <string.h>
  38. #include <ctype.h>
  39. #ifdef HAVE_SYS_SELECT_H
  40. # include <sys/select.h>
  41. #endif
  42. #ifdef __linux__
  43. # if defined(__GLIBC__) && (__GLIBC__ < 2)
  44. # include <linux/termios.h> /* This is needed for TIOCLINUX */
  45. # else
  46. # include <termios.h>
  47. # endif
  48. # include <sys/ioctl.h>
  49. #endif
  50. #include "../src/util.h"
  51. #include "vfs.h"
  52. #include "callback.h"
  53. #ifndef VFS_STANDALONE
  54. #error This has only sense when compiling standalone version
  55. #endif
  56. int source_route = 0;
  57. int cd_symlinks = 0;
  58. /*
  59. * Required functions to make mc's vfs layer compile stand-alone
  60. */
  61. void *do_xmalloc (int size)
  62. {
  63. void *m = malloc (size);
  64. if (!m)
  65. vfs_die ("Memory exhausted\n");
  66. return m;
  67. }
  68. /*
  69. * We do not want/need many of midnight's functions, stub routines.
  70. */
  71. void
  72. enable_interrupt_key (void)
  73. {
  74. }
  75. void
  76. disable_interrupt_key (void)
  77. {
  78. }
  79. int got_interrupt (void)
  80. {
  81. return 0;
  82. }
  83. void
  84. rotate_dash (void)
  85. {
  86. }
  87. char *
  88. load_anon_passwd (void)
  89. {
  90. return NULL;
  91. }
  92. static char (*callbacks[NUM_CALLBACKS])(char *msg) = { NULL, NULL, NULL, };
  93. void
  94. vfs_set_callback (int num, void *func)
  95. {
  96. if (num >= NUM_CALLBACKS)
  97. vfs_die ("Attempt to set invalid callback.\n");
  98. callbacks [num] = func;
  99. }
  100. static void
  101. info_puts( char *s )
  102. {
  103. if (!callbacks [CALL_INFO])
  104. fprintf (stderr, "%s\n", s);
  105. else
  106. callbacks [CALL_INFO](s);
  107. }
  108. static void
  109. box_puts( char *s )
  110. {
  111. if (!callbacks [CALL_BOX])
  112. fprintf (stderr, "%s\n", s);
  113. else
  114. callbacks [CALL_BOX](s);
  115. }
  116. char *
  117. vfs_get_password (char *msg)
  118. {
  119. if (!callbacks [CALL_PASSWD])
  120. return NULL;
  121. else
  122. callbacks [CALL_PASSWD](msg);
  123. }
  124. void
  125. print_vfs_message (char *msg, ...)
  126. {
  127. char *str;
  128. va_list args;
  129. va_start (args,msg);
  130. str = g_strdup_vprintf (msg, args);
  131. va_end (args);
  132. info_puts (str);
  133. g_free (str);
  134. }
  135. void
  136. wipe_password (char *passwd)
  137. {
  138. char *p = passwd;
  139. for (;*p; p++)
  140. *p = 0;
  141. free (passwd);
  142. }
  143. int
  144. exist_file (char *name)
  145. {
  146. return access (name, R_OK) == 0;
  147. }
  148. void
  149. message_1s (int i, char *c1, char *c2)
  150. {
  151. char buf [4096];
  152. snprintf (buf, sizeof (buf), "%s %s", c1, c2);
  153. box_puts (buf);
  154. }
  155. void
  156. message_2s (int i, char *c1, char *c2, char *c3)
  157. {
  158. char buf [4096];
  159. snprintf (buf, sizeof (buf), "%s %s %s", c1, c2, c3 );
  160. box_puts (buf );
  161. }
  162. void
  163. message_3s( int i, char *c1, char *c2, char *c3, const char *c4 )
  164. {
  165. char buf [4096];
  166. snprintf (buf, sizeof (buf), "%s %s %s %s", c1, c2, c3, c4);
  167. box_puts (buf);
  168. }
  169. void vfs_init( void );
  170. void ftpfs_init_passwd( void );
  171. char *mc_home = LIBDIR;
  172. void
  173. mc_vfs_init( void )
  174. {
  175. vfs_init();
  176. ftpfs_init_passwd();
  177. }
  178. void
  179. mc_vfs_done( void )
  180. {
  181. vfs_shut();
  182. }