Пример #1
0
/* Return pointer to copy of filename in the command buffer */
static const char * get_filename( const char ** const ibufpp )
  {
  static char * buf = 0;
  static int bufsz = 0;
  int size, n;

  *ibufpp = skip_blanks( *ibufpp );
  if( **ibufpp != '\n' )
    {
    if( !get_extended_line( ibufpp, &size, true ) ) return 0;
    if( **ibufpp == '!' )
      {
      ++*ibufpp;
      return get_shell_command( ibufpp );
      }
    else if( size > path_max( 0 ) )
      { set_error_msg( "Filename too long" ); return 0; }
    }
  else if( !traditional() && !def_filename[0] )
    { set_error_msg( "No current filename" ); return 0; }
  if( !resize_buffer( &buf, &bufsz, path_max( 0 ) + 1 ) ) return 0;
  for( n = 0; **ibufpp != '\n'; ++n, ++*ibufpp ) buf[n] = **ibufpp;
  buf[n] = 0;
  while( **ibufpp == '\n' ) ++*ibufpp;			/* skip newline */
  return ( may_access_filename( buf ) ? buf : 0 );
  }
Пример #2
0
static void sighup_handler( int signum )
  {
  if( signum ) {}			/* keep compiler happy */
  if( mutex ) sighup_pending = true;
  else
    {
    const char hb[] = "ed.hup";
    sighup_pending = false;
    if( last_addr() && modified() &&
        write_file( hb, "w", 1, last_addr() ) < 0 )
      {
      char * const s = getenv( "HOME" );
      const int len = ( s ? strlen( s ) : 0 );
      const int need_slash = ( ( !len || s[len-1] != '/' ) ? 1 : 0 );
      char * const hup = ( ( len + need_slash + (int)sizeof hb < path_max( 0 ) ) ?
                    (char *) malloc( len + need_slash + sizeof hb ) : 0 );
      if( len && hup )			/* hup filename */
        {
        memcpy( hup, s, len );
        if( need_slash ) hup[len] = '/';
        memcpy( hup + len + need_slash, hb, sizeof hb );
        if( write_file( hup, "w", 1, last_addr() ) >= 0 ) exit( 0 );
        }
      exit( 1 );			/* hup file write failed */
      }
    exit( 0 );
    }
  }