コード例 #1
0
ファイル: fileio.c プロジェクト: vathpela/systemd
static void write_env_var(FILE *f, const char *v) {
        const char *p;

        p = strchr(v, '=');
        if (!p) {
                /* Fallback */
                fputs_unlocked(v, f);
                fputc_unlocked('\n', f);
                return;
        }

        p++;
        fwrite_unlocked(v, 1, p-v, f);

        if (string_has_cc(p, NULL) || chars_intersect(p, WHITESPACE SHELL_NEED_QUOTES)) {
                fputc_unlocked('\"', f);

                for (; *p; p++) {
                        if (strchr(SHELL_NEED_ESCAPE, *p))
                                fputc_unlocked('\\', f);

                        fputc_unlocked(*p, f);
                }

                fputc_unlocked('\"', f);
        } else
                fputs_unlocked(p, f);

        fputc_unlocked('\n', f);
}
コード例 #2
0
ファイル: resolved-resolv-conf.c プロジェクト: andir/systemd
static void write_resolv_conf_search(
                OrderedSet *domains,
                FILE *f) {
        unsigned length = 0, count = 0;
        Iterator i;
        char *domain;

        assert(domains);
        assert(f);

        fputs_unlocked("search", f);

        ORDERED_SET_FOREACH(domain, domains, i) {
                if (++count > MAXDNSRCH) {
                        fputs_unlocked("\n# Too many search domains configured, remaining ones ignored.", f);
                        break;
                }
                length += strlen(domain) + 1;
                if (length > 256) {
                        fputs_unlocked("\n# Total length of all search domains is too long, remaining ones ignored.", f);
                        break;
                }
                fputc_unlocked(' ', f);
                fputs_unlocked(domain, f);
        }

        fputs_unlocked("\n", f);
}
コード例 #3
0
ファイル: resolved-resolv-conf.c プロジェクト: andir/systemd
static int write_resolv_conf_contents(FILE *f, OrderedSet *dns, OrderedSet *domains) {
        Iterator i;

        fputs_unlocked("# This file is managed by man:systemd-resolved(8). Do not edit.\n#\n"
                       "# This is a dynamic resolv.conf file for connecting local clients directly to\n"
                       "# all known DNS servers.\n#\n"
                       "# Third party programs must not access this file directly, but only through the\n"
                       "# symlink at /etc/resolv.conf. To manage man:resolv.conf(5) in a different way,\n"
                       "# replace this symlink by a static file or a different symlink.\n#\n"
                       "# See man:systemd-resolved.service(8) for details about the supported modes of\n"
                       "# operation for /etc/resolv.conf.\n\n", f);

        if (ordered_set_isempty(dns))
                fputs_unlocked("# No DNS servers known.\n", f);
        else {
                unsigned count = 0;
                DnsServer *s;

                ORDERED_SET_FOREACH(s, dns, i)
                        write_resolv_conf_server(s, f, &count);
        }

        if (!ordered_set_isempty(domains))
                write_resolv_conf_search(domains, f);

        return fflush_and_check(f);
}
コード例 #4
0
ファイル: main.c プロジェクト: hholzgra/hartmut-pbf2osm
void printescape(unsigned char *s, unsigned int l) {
    for (unsigned int i = 0; i < l; i++) {
        switch (s[i]) {
            case '<':
                fputs_unlocked("&#60;", stdout);
                continue;
            case '>':
                fputs_unlocked("&#62;", stdout);
                continue;
            case '&':
                fputs_unlocked("&#38;", stdout);
                continue;
            case '\'':
                fputs_unlocked("&#39;", stdout);
                continue;
            case '"':
                fputs_unlocked("&#34;", stdout);
                continue;
            case '\r':
                fputs_unlocked("&#13;", stdout);
                continue;
            case '\n':
                fputs_unlocked("&#10;", stdout);
                continue;
            case '\t':
                fputs_unlocked("&#9;", stdout);
                continue;
            default:
                fputc_unlocked(s[i], stdout);
        }
    }
}
コード例 #5
0
ファイル: resolved-resolv-conf.c プロジェクト: andir/systemd
static void write_resolv_conf_server(DnsServer *s, FILE *f, unsigned *count) {
        assert(s);
        assert(f);
        assert(count);

        if (!dns_server_string(s)) {
                log_warning("Our of memory, or invalid DNS address. Ignoring server.");
                return;
        }

        /* Check if the DNS server is limited to particular domains;
         * resolv.conf does not have a syntax to express that, so it must not
         * appear as a global name server to avoid routing unrelated domains to
         * it (which is a privacy violation, will most probably fail anyway,
         * and adds unnecessary load) */
        if (dns_server_limited_domains(s)) {
                log_debug("DNS server %s has route-only domains, not using as global name server", dns_server_string(s));
                return;
        }

        if (*count == MAXNS)
                fputs_unlocked("# Too many DNS servers configured, the following entries may be ignored.\n", f);
        (*count)++;

        fprintf(f, "nameserver %s\n", dns_server_string(s));
}
コード例 #6
0
ファイル: err.c プロジェクト: ZoneMo/Learn-SourceCode
void
vwarn (const char *format, __gnuc_va_list ap)
{
  int error = errno;

  flockfile (stderr);
  if (_IO_fwide (stderr, 0) > 0)
    {
      __fwprintf (stderr, L"%s: ", __progname);
      if (format)
	{
	  convert_and_print (format, ap);
	  fputws_unlocked (L": ", stderr);
	}
      __set_errno (error);
      __fwprintf (stderr, L"%m\n");
    }
  else
    {
      fprintf (stderr, "%s: ", __progname);
      if (format)
	{
	  vfprintf (stderr, format, ap);
	  fputs_unlocked (": ", stderr);
	}
      __set_errno (error);
      fprintf (stderr, "%m\n");
    }
  funlockfile (stderr);
}
コード例 #7
0
ファイル: fastaredux-3.c プロジェクト: chubbymaggie/tinyvm
void
randomize(struct amino_acid *amino_acid, int amino_acid_size,
        const char *title, int n, random_t *rand) {
    struct amino_acid *lookup[LOOKUP_SIZE];
    char line_buffer[LINE_LEN + 1];
    int i, j;

    line_buffer[LINE_LEN] = '\n';

    fill_lookup(lookup, amino_acid, amino_acid_size);

    fputs_unlocked(title, stdout);

    for (i = 0, j = 0; i < n; i++, j++) {
        if (j == LINE_LEN) {
            fwrite_unlocked(line_buffer, LINE_LEN + 1, 1, stdout);
            j = 0;
        }

        float r = random_next_lookup(rand);
        struct amino_acid *u = lookup[(short)r];
        while (unlikely(u->cprob_lookup < r)) {
            ++u;
        }
        line_buffer[j] = u->sym;
    }
    line_buffer[j] = '\n';
    fwrite_unlocked(line_buffer, j + 1, 1, stdout);
}
コード例 #8
0
ファイル: pr38360.c プロジェクト: 0day-ci/gcc
int
main ()
{
  fputs ("");
  fputs_unlocked ("");
  return 0;
}
コード例 #9
0
ファイル: envsubst.c プロジェクト: izabera/inutility
// parse a var after $
char *getvar(FILE *input, FILE *fail) {
  int braces = 0, c;
  if ((c = getc_unlocked(input)) == EOF) return NULL;
  if (c == '{') {
    putc_unlocked(c, fail);
    braces = 1;
  }
  else ungetc(c, input);

  if ((c = getc_unlocked(input)) == EOF) return NULL;
  if (!isalpha(c) && c != '_') {
    putc_unlocked(c, fail);
    return NULL;
  }

  ungetc(c, input);
  char *var;
  fscanf(input, "%m[A-Za-z0-9_]", &var);
  if (!var) return NULL;
  fputs_unlocked(var, fail);

  if (braces) {
    if ((c = getchar_unlocked()) == EOF) return NULL;
    putc_unlocked(c, fail);
    if (c != '}') {
      ungetc(c, input);
      return NULL;
    }
  }
  return var;
}
コード例 #10
0
ファイル: fedora2_true.c プロジェクト: CoolOppo/boomerang
// address: 8048a30
void proc4(int param1) {
    __size32 eax; 		// r24
    int edx; 		// r26

    dcgettext(0, "Usage: %s [ignored command line arguments]\n  or:  %s OPTION\nExit with a status code indicating success.\n\nThese option names may not be abbreviated.\n\n", 5);
    printf(eax);
    dcgettext(0, "      --help     display this help and exit\n", 5);
    edx = *0x804b7e0;
    fputs_unlocked(eax, edx);
    dcgettext(0, "      --version  output version information and exit\n", 5);
    edx = *0x804b7e0;
    fputs_unlocked(eax, edx);
    dcgettext(0, "\nReport bugs to <%s>.\n", 5);
    printf(eax);
    exit(param1);
    return;
}
コード例 #11
0
ファイル: cut.c プロジェクト: anti-patterns/genprog-corebench
void usage(int status ) 
{ char *tmp ;
  char *tmp___0 ;
  char *tmp___1 ;
  char *tmp___2 ;
  char *tmp___3 ;
  char *tmp___4 ;
  char *tmp___5 ;
  char *tmp___6 ;
  char *tmp___7 ;
  char *tmp___8 ;
  char *tmp___9 ;
  char *tmp___10 ;

  {
  if (status != 0) {
    tmp = gettext("Try `%s --help\' for more information.\n");
    fprintf((FILE */* __restrict  */)stderr, (char const   */* __restrict  */)tmp, program_name);
  } else {
    tmp___0 = gettext("Usage: %s OPTION... [FILE]...\n");
    printf((char const   */* __restrict  */)tmp___0, program_name);
    tmp___1 = gettext("Print selected parts of lines from each FILE to standard output.\n\n");
    fputs_unlocked((char const   */* __restrict  */)tmp___1, (FILE */* __restrict  */)stdout);
    tmp___2 = gettext("Mandatory arguments to long options are mandatory for short options too.\n");
    fputs_unlocked((char const   */* __restrict  */)tmp___2, (FILE */* __restrict  */)stdout);
    tmp___3 = gettext("  -b, --bytes=LIST        select only these bytes\n  -c, --characters=LIST   select only these characters\n  -d, --delimiter=DELIM   use DELIM instead of TAB for field delimiter\n");
    fputs_unlocked((char const   */* __restrict  */)tmp___3, (FILE */* __restrict  */)stdout);
    tmp___4 = gettext("  -f, --fields=LIST       select only these fields;  also print any line\n                            that contains no delimiter character, unless\n                            the -s option is specified\n  -n                      (ignored)\n");
    fputs_unlocked((char const   */* __restrict  */)tmp___4, (FILE */* __restrict  */)stdout);
    tmp___5 = gettext("      --complement        complement the set of selected bytes, characters\n                            or fields\n");
    fputs_unlocked((char const   */* __restrict  */)tmp___5, (FILE */* __restrict  */)stdout);
    tmp___6 = gettext("  -s, --only-delimited    do not print lines not containing delimiters\n      --output-delimiter=STRING  use STRING as the output delimiter\n                            the default is to use the input delimiter\n");
    fputs_unlocked((char const   */* __restrict  */)tmp___6, (FILE */* __restrict  */)stdout);
    tmp___7 = gettext("      --help     display this help and exit\n");
    fputs_unlocked((char const   */* __restrict  */)tmp___7, (FILE */* __restrict  */)stdout);
    tmp___8 = gettext("      --version  output version information and exit\n");
    fputs_unlocked((char const   */* __restrict  */)tmp___8, (FILE */* __restrict  */)stdout);
    tmp___9 = gettext("\nUse one, and only one of -b, -c or -f.  Each LIST is made up of one\nrange, or many ranges separated by commas.  Selected input is written\nin the same order that it is read, and is written exactly once.\n");
    fputs_unlocked((char const   */* __restrict  */)tmp___9, (FILE */* __restrict  */)stdout);
    tmp___10 = gettext("Each range is one of:\n\n  N     N\'th byte, character or field, counted from 1\n  N-    from N\'th byte, character or field, to end of line\n  N-M   from N\'th to M\'th (included) byte, character or field\n  -M    from first to M\'th (included) byte, character or field\n\nWith no FILE, or when FILE is -, read standard input.\n");
    fputs_unlocked((char const   */* __restrict  */)tmp___10, (FILE */* __restrict  */)stdout);
    emit_ancillary_info();
  }
  exit(status);
}
}
コード例 #12
0
ファイル: perf.cpp プロジェクト: adob/print-stmt
void use_fputs_unlocked() {
    flockfile(stdout);
    
    const char *s1 = "string='";
    const char *s2 = "' count='";
    const char *s3 = "'\n";
    char buf[100];
    
    fputs_unlocked(s1, stdout);
    fputs_unlocked(string, stdout);
    fputs_unlocked(s2, stdout);
    
    snprintf(buf, sizeof buf, "%d", count);
    fputs_unlocked(buf, stdout);
    
    fputs_unlocked(s3, stdout);
    
    funlockfile(stdout);
}
コード例 #13
0
void version_etc_va( FILE *stream, char *command_name, char *package, char *version, va_list authors )
{
  size_t n_authors;
{
  va_list tmp_authors = authors;
  n_authors = 0;
  while ( tmp_authors += 4, tmp_authors[0] != 0 )
  {
    n_authors++;
  }
  if ( command_name != 0 )
    fprintf( stream, "%s (%s) %s\n", command_name, package, version );
  else
    fprintf( stream, "%s %s\n", package, version );
  fprintf( stream, version_etc_copyright, gettext( "(C)" ), 2008 );
  fputs_unlocked( gettext( "\nLicense GPLv3+: GNU GPL version 3 or later &lt;http://gnu.org/licenses/gpl.html&gt;\nThis is free software: you are free to change and redistribute it.\nThere is NO WARRANTY, to the extent permitted by law.\n\n" ), stream );
  switch ( n_authors )
  {
  case 0:
    abort( );
    break;
  case 1:
    rpl_vfprintf( stream, gettext( "Written by %s.\n" ), authors );
    break;
  case 2:
    rpl_vfprintf( stream, gettext( "Written by %s and %s.\n" ), authors );
    break;
  case 3:
    rpl_vfprintf( stream, gettext( "Written by %s, %s, and %s.\n" ), authors );
    break;
  case 4:
    rpl_vfprintf( stream, gettext( "Written by %s, %s, %s,\nand %s.\n" ), authors );
    break;
  case 5:
    rpl_vfprintf( stream, gettext( "Written by %s, %s, %s,\n%s, and %s.\n" ), authors );
    break;
  case 6:
    rpl_vfprintf( stream, gettext( "Written by %s, %s, %s,\n%s, %s, and %s.\n" ), authors );
    break;
  case 7:
    rpl_vfprintf( stream, gettext( "Written by %s, %s, %s,\n%s, %s, %s, and %s.\n" ), authors );
    break;
  case 8:
    rpl_vfprintf( stream, gettext( "Written by %s, %s, %s,\n%s, %s, %s, %s,\nand %s.\n" ), authors );
    break;
  case 9:
    rpl_vfprintf( stream, gettext( "Written by %s, %s, %s,\n%s, %s, %s, %s,\n%s, and %s.\n" ), authors );
    break;
  default:
    rpl_vfprintf( stream, gettext( "Written by %s, %s, %s,\n%s, %s, %s, %s,\n%s, %s, and others.\n" ), authors );
    return;
    break;
  }
}
}
コード例 #14
0
ファイル: gen_rrg.cpp プロジェクト: ryuhei-mori/gen_rrg
void write_uint(int x){
  int i;
  static char buf[12];
  if(x==0){
    putchar_unlocked('0');
    return;
  }

  for(i=10; x; i--){
    buf[i] = '0' + x % 10;
    x /= 10;
  }
  fputs_unlocked(buf+1+i, stdout);
}
コード例 #15
0
int _find_steals(Node * ptr, char * hist, char* limit, char level, FILE * out_file){
    int i;

    if(level == 26){
        for(i = 0; i < ptr->len; i++){
            fputs_unlocked((char *)ptr->children[i], out_file);
            fputc_unlocked('\n', out_file);
        }
        return 0;
    }

    for (i = hist[level]; i < ptr->len && !(limit && i > hist[level] + limit[level]); i++)
        if(ptr->children[i])
            _find_steals(ptr->children[i], hist, limit, level + 1, out_file);

    return 0;
}
コード例 #16
0
ファイル: main.c プロジェクト: hholzgra/hartmut-pbf2osm
void itoa(int value) {
    char result[20];
    
    char* ptr = result + sizeof(result);
    int tmp_value;
    
    *--ptr = '\0';
    do {
        tmp_value = value;
        value /= 10;
	*--ptr = "9876543210123456789"[9 + (tmp_value - value*10)];
    } while ( value );
    
    if (tmp_value < 0) *--ptr = '-';
    
    fputs_unlocked(ptr, stdout);
}
コード例 #17
0
ファイル: err.c プロジェクト: avokhmin/RPM5
void
vwarn (const char *format, __gnuc_va_list ap)
{
  int error = errno;

  flockfile (stderr);
  if (__progname)
    fprintf (stderr, "%s: ", __progname);
  if (format)
    {
      vfprintf (stderr, format, ap);
      fputs_unlocked (": ", stderr);
    }
  __set_errno (error);
  fprintf (stderr, "%m\n");
  funlockfile (stderr);
}
コード例 #18
0
ファイル: stdio.c プロジェクト: luckboy/uportlibc
int puts(const char *str)
{
  int res;
  lock_lock(&(stdout->lock));
  do {
    res = fputs_unlocked(str, stdout);
    if(res == EOF) {
      res = EOF;
      break;
    }
    if(putchar_unlocked('\n') == EOF) {
      res = EOF;
      break;
    }
    res++;
  } while(0);
  lock_unlock(&(stdout->lock));
  return res;
}
コード例 #19
0
ファイル: cut.c プロジェクト: anti-patterns/genprog-corebench
__inline static void emit_ancillary_info(void) 
{ char *tmp ;
  char *tmp___0 ;
  char *tmp___1 ;
  char *tmp___2 ;
  char const   *lc_messages ;
  char *tmp___3 ;
  char *tmp___4 ;
  char *tmp___5 ;
  int tmp___6 ;
  char *tmp___7 ;
  char *tmp___8 ;

  {
  tmp = last_component(program_name);
  tmp___0 = gettext("\nReport %s bugs to %s\n");
  printf((char const   */* __restrict  */)tmp___0, tmp, "*****@*****.**");
  tmp___1 = gettext("%s home page: <http://www.gnu.org/software/%s/>\n");
  printf((char const   */* __restrict  */)tmp___1, "GNU coreutils", "coreutils");
  tmp___2 = gettext("General help using GNU software: <http://www.gnu.org/gethelp/>\n");
  fputs_unlocked((char const   */* __restrict  */)tmp___2, (FILE */* __restrict  */)stdout);
  tmp___3 = setlocale(5, (char const   *)((void *)0));
  lc_messages = (char const   *)tmp___3;
  if (lc_messages) {
    tmp___6 = strncmp(lc_messages, "en_", 3UL);
    if (tmp___6) {
      tmp___4 = last_component(program_name);
      tmp___5 = gettext("Report %s translation bugs to <http://translationproject.org/team/>\n");
      printf((char const   */* __restrict  */)tmp___5, tmp___4);
    } else {

    }
  } else {

  }
  tmp___7 = last_component(program_name);
  tmp___8 = gettext("For complete documentation, run: info coreutils \'%s invocation\'\n");
  printf((char const   */* __restrict  */)tmp___8, tmp___7);
  return;
}
}
コード例 #20
0
ファイル: session.c プロジェクト: rainsome-org1/cockpit
static void
write_auth_string (const char *field,
                   const char *str)
{
  const unsigned char *at;
  char buf[8];

  fprintf (authf, ", \"%s\": \"", field);
  for (at = (const unsigned char *)str; *at; at++)
    {
      if (*at == '\\' || *at == '\"' || *at < 0x1f)
        {
          snprintf (buf, sizeof (buf), "\\u%04x", (int)*at);
          fputs_unlocked (buf, authf);
        }
      else
        {
          fputc_unlocked (*at, authf);
        }
    }
  fputc_unlocked ('\"', authf);
}
コード例 #21
0
ファイル: fastaredux-3.c プロジェクト: chubbymaggie/tinyvm
void
repeat(const char *alu, const char *title, int n) {
    int len = strlen(alu);
    char buffer[len + LINE_LEN];
    int pos = 0;

    memcpy(buffer, alu, len);
    memcpy(buffer + len, alu, LINE_LEN);

    fputs_unlocked(title, stdout);
    while (n > 0) {
        int bytes = n > LINE_LEN ? LINE_LEN : n;

        fwrite_unlocked(buffer + pos, bytes, 1, stdout);
        pos += bytes;
        if (pos > len) {
            pos -= len;
        }
        fputc_unlocked('\n', stdout);
        n -= bytes;
    }
}
コード例 #22
0
static int write_stub_resolv_conf_contents(FILE *f, OrderedSet *dns, OrderedSet *domains) {
        fputs_unlocked("# This file is managed by man:systemd-resolved(8). Do not edit.\n"
                       "#\n"
                       "# This is a dynamic resolv.conf file for connecting local clients to the\n"
                       "# internal DNS stub resolver of systemd-resolved. This file lists all\n"
                       "# configured search domains.\n"
                       "#\n"
                       "# Run \"resolvectl status\" to see details about the uplink DNS servers\n"
                       "# currently in use.\n"
                       "#\n"
                       "# Third party programs must not access this file directly, but only through the\n"
                       "# symlink at /etc/resolv.conf. To manage man:resolv.conf(5) in a different way,\n"
                       "# replace this symlink by a static file or a different symlink.\n"
                       "#\n"
                       "# See man:systemd-resolved.service(8) for details about the supported modes of\n"
                       "# operation for /etc/resolv.conf.\n"
                       "\n"
                       "nameserver 127.0.0.53\n", f);

        if (!ordered_set_isempty(domains))
                write_resolv_conf_search(domains, f);

        return fflush_and_check(f);
}
コード例 #23
0
ファイル: dmn_log.c プロジェクト: guozi058/gdnsd
void dmn_loggerv(int level, const char* fmt, va_list ap) {
    if(alt_stderr) {
#ifndef NDEBUG

        time_t t = time(NULL);
        struct tm tmp;
        localtime_r(&t, &tmp);
        char tstamp[10];
        if(!strftime(tstamp, 10, "%T ", &tmp))
            strcpy(tstamp, "--:--:-- ");

#  if defined SYS_gettid && !defined __APPLE__
        pid_t tid = syscall(SYS_gettid);
        char tidbuf[16];
        snprintf(tidbuf, 16, " [%i]", tid);
#  endif

        const char* pfx;
        switch(level) {
            case LOG_DEBUG: pfx = pfx_debug; break;
            case LOG_INFO: pfx = pfx_info; break;
            case LOG_WARNING: pfx = pfx_warning; break;
            case LOG_ERR: pfx = pfx_err; break;
            case LOG_CRIT: pfx = pfx_crit; break;
            default: pfx = pfx_unknown; break;
        }
        flockfile(alt_stderr);
        fputs_unlocked(tstamp, alt_stderr);
        if(our_logname)
            fputs_unlocked(our_logname, alt_stderr);
#  if defined SYS_gettid && !defined __APPLE__
        fputs_unlocked(tidbuf, alt_stderr);
#  endif
        fputs_unlocked(pfx, alt_stderr);
        va_list apcpy;
        va_copy(apcpy, ap);
        vfprintf(alt_stderr, fmt, apcpy);
        va_end(apcpy);
        putc_unlocked('\n', alt_stderr);
        fflush_unlocked(alt_stderr);
        funlockfile(alt_stderr);

#else // NDEBUG
        if(level != LOG_INFO || send_stderr_info) {
            va_list apcpy;
            va_copy(apcpy, ap);
            flockfile(alt_stderr);
            vfprintf(alt_stderr, fmt, apcpy);
            va_end(apcpy);
            putc_unlocked('\n', alt_stderr);
            fflush_unlocked(alt_stderr);
            funlockfile(alt_stderr);
        }
#endif // NDEBUG
    }

    if(dmn_syslog_alive)
        vsyslog(level, fmt, ap);

    dmn_fmtbuf_reset();
}
コード例 #24
0
ファイル: getpass.c プロジェクト: djmitche/gnulib
char *
getpass (const char *prompt)
{
  FILE *tty;
  FILE *in, *out;
  struct termios s, t;
  bool tty_changed = false;
  static char *buf;
  static size_t bufsize;
  ssize_t nread;

  /* Try to write to and read from the terminal if we can.
     If we can't open the terminal, use stderr and stdin.  */

  tty = fopen ("/dev/tty", "w+");
  if (tty == NULL)
    {
      in = stdin;
      out = stderr;
    }
  else
    {
      /* We do the locking ourselves.  */
      __fsetlocking (tty, FSETLOCKING_BYCALLER);

      out = in = tty;
    }

  flockfile (out);

  /* Turn echoing off if it is on now.  */
#if HAVE_TCGETATTR
  if (tcgetattr (fileno (in), &t) == 0)
    {
      /* Save the old one. */
      s = t;
      /* Tricky, tricky. */
      t.c_lflag &= ~(ECHO | ISIG);
      tty_changed = (tcsetattr (fileno (in), TCSAFLUSH | TCSASOFT, &t) == 0);
    }
#endif

  /* Write the prompt.  */
  fputs_unlocked (prompt, out);
  fflush_unlocked (out);

  /* Read the password.  */
  nread = getline (&buf, &bufsize, in);

  /* According to the C standard, input may not be followed by output
     on the same stream without an intervening call to a file
     positioning function.  Suppose in == out; then without this fseek
     call, on Solaris, HP-UX, AIX, OSF/1, the previous input gets
     echoed, whereas on IRIX, the following newline is not output as
     it should be.  POSIX imposes similar restrictions if fileno (in)
     == fileno (out).  The POSIX restrictions are tricky and change
     from POSIX version to POSIX version, so play it safe and invoke
     fseek even if in != out.  */
  fseeko (out, 0, SEEK_CUR);

  if (buf != NULL)
    {
      if (nread < 0)
        buf[0] = '\0';
      else if (buf[nread - 1] == '\n')
        {
          /* Remove the newline.  */
          buf[nread - 1] = '\0';
          if (tty_changed)
            {
              /* Write the newline that was not echoed.  */
              putc_unlocked ('\n', out);
            }
        }
    }

  /* Restore the original setting.  */
#if HAVE_TCSETATTR
  if (tty_changed)
    tcsetattr (fileno (in), TCSAFLUSH | TCSASOFT, &s);
#endif

  funlockfile (out);

  call_fclose (tty);

  return buf;
}
コード例 #25
0
ファイル: syslog.c プロジェクト: jameshilliard/20-4-4
void
__vsyslog_chk(int pri, int flag, const char *fmt, va_list ap)
{
	struct tm now_tm;
	time_t now;
	int fd;
	FILE *f;
	char *buf = 0;
	size_t bufsize = 0;
	size_t prioff, msgoff;
#ifndef NO_SIGPIPE
 	struct sigaction action, oldaction;
 	int sigpipe;
#endif
	int saved_errno = errno;
	char failbuf[3 * sizeof (pid_t) + sizeof "out of memory []"];

#define	INTERNALLOG	LOG_ERR|LOG_CONS|LOG_PERROR|LOG_PID
	/* Check for invalid bits. */
	if (pri & ~(LOG_PRIMASK|LOG_FACMASK)) {
		syslog(INTERNALLOG,
		    "syslog: unknown facility/priority: %x", pri);
		pri &= LOG_PRIMASK|LOG_FACMASK;
	}

	/* Check priority against setlogmask values. */
	if ((LOG_MASK (LOG_PRI (pri)) & LogMask) == 0)
		return;

	/* Set default facility if none specified. */
	if ((pri & LOG_FACMASK) == 0)
		pri |= LogFacility;

	/* Build the message in a memory-buffer stream.  */
	f = open_memstream (&buf, &bufsize);
	if (f == NULL)
	  {
	    /* We cannot get a stream.  There is not much we can do but
	       emitting an error messages.  */
	    char numbuf[3 * sizeof (pid_t)];
	    char *nump;
	    char *endp = __stpcpy (failbuf, "out of memory [");
	    pid_t pid = __getpid ();

	    nump = numbuf + sizeof (numbuf);
	    /* The PID can never be zero.  */
	    do
	      *--nump = '0' + pid % 10;
	    while ((pid /= 10) != 0);

	    endp = __mempcpy (endp, nump, (numbuf + sizeof (numbuf)) - nump);
	    *endp++ = ']';
	    *endp = '\0';
	    buf = failbuf;
	    bufsize = endp - failbuf;
	    msgoff = 0;
	  }
	else
	  {
	    __fsetlocking (f, FSETLOCKING_BYCALLER);
	    prioff = fprintf (f, "<%d>", pri);
	    (void) time (&now);
	    f->_IO_write_ptr += __strftime_l (f->_IO_write_ptr,
					      f->_IO_write_end
					      - f->_IO_write_ptr,
					      "%h %e %T ",
					      __localtime_r (&now, &now_tm),
					      _nl_C_locobj_ptr);
	    msgoff = ftell (f);
	    if (LogTag == NULL)
	      LogTag = __progname;
	    if (LogTag != NULL)
	      fputs_unlocked (LogTag, f);
	    if (LogStat & LOG_PID)
	      fprintf (f, "[%d]", (int) __getpid ());
	    if (LogTag != NULL)
	      {
		putc_unlocked (':', f);
		putc_unlocked (' ', f);
	      }

	    /* Restore errno for %m format.  */
	    __set_errno (saved_errno);

	    /* We have the header.  Print the user's format into the
               buffer.  */
	    if (flag == -1)
	      vfprintf (f, fmt, ap);
	    else
	      __vfprintf_chk (f, flag, fmt, ap);

	    /* Close the memory stream; this will finalize the data
	       into a malloc'd buffer in BUF.  */
	    fclose (f);
	  }

	/* Output to stderr if requested. */
	if (LogStat & LOG_PERROR) {
		struct iovec iov[2];
		register struct iovec *v = iov;

		v->iov_base = buf + msgoff;
		v->iov_len = bufsize - msgoff;
		/* Append a newline if necessary.  */
		if (buf[bufsize - 1] != '\n')
		  {
		    ++v;
		    v->iov_base = (char *) "\n";
		    v->iov_len = 1;
		  }

		__libc_cleanup_push (free, buf == failbuf ? NULL : buf);

		/* writev is a cancellation point.  */
		(void)__writev(STDERR_FILENO, iov, v - iov + 1);

		__libc_cleanup_pop (0);
	}

	/* Prepare for multiple users.  We have to take care: open and
	   write are cancellation points.  */
	struct cleanup_arg clarg;
	clarg.buf = buf;
	clarg.oldaction = NULL;
	__libc_cleanup_push (cancel_handler, &clarg);
	__libc_lock_lock (syslog_lock);

#ifndef NO_SIGPIPE
	/* Prepare for a broken connection.  */
 	memset (&action, 0, sizeof (action));
 	action.sa_handler = sigpipe_handler;
 	sigemptyset (&action.sa_mask);
 	sigpipe = __sigaction (SIGPIPE, &action, &oldaction);
	if (sigpipe == 0)
	  clarg.oldaction = &oldaction;
#endif

	/* Get connected, output the message to the local logger. */
	if (!connected)
		openlog_internal(LogTag, LogStat | LOG_NDELAY, 0);

	/* If we have a SOCK_STREAM connection, also send ASCII NUL as
	   a record terminator.  */
	if (LogType == SOCK_STREAM)
	  ++bufsize;

	if (!connected || __send(LogFile, buf, bufsize, send_flags) < 0)
	  {
	    if (connected)
	      {
		/* Try to reopen the syslog connection.  Maybe it went
		   down.  */
		closelog_internal ();
		openlog_internal(LogTag, LogStat | LOG_NDELAY, 0);
	      }

	    if (!connected || __send(LogFile, buf, bufsize, send_flags) < 0)
	      {
		closelog_internal ();	/* attempt re-open next time */
		/*
		 * Output the message to the console; don't worry
		 * about blocking, if console blocks everything will.
		 * Make sure the error reported is the one from the
		 * syslogd failure.
		 */
		if (LogStat & LOG_CONS &&
		    (fd = __open(_PATH_CONSOLE, O_WRONLY|O_NOCTTY, 0)) >= 0)
		  {
		    dprintf (fd, "%s\r\n", buf + msgoff);
		    (void)__close(fd);
		  }
	      }
	  }

#ifndef NO_SIGPIPE
	if (sigpipe == 0)
		__sigaction (SIGPIPE, &oldaction, (struct sigaction *) NULL);
#endif

	/* End of critical section.  */
	__libc_cleanup_pop (0);
	__libc_lock_unlock (syslog_lock);

	if (buf != failbuf)
		free (buf);
}
コード例 #26
0
ファイル: fstab-generator.c プロジェクト: OpenDZ/systemd
static int add_swap(
                const char *what,
                struct mntent *me,
                bool noauto,
                bool nofail) {

        _cleanup_free_ char *name = NULL, *unit = NULL;
        _cleanup_fclose_ FILE *f = NULL;
        int r;

        assert(what);
        assert(me);

        if (access("/proc/swaps", F_OK) < 0) {
                log_info("Swap not supported, ignoring fstab swap entry for %s.", what);
                return 0;
        }

        if (detect_container() > 0) {
                log_info("Running in a container, ignoring fstab swap entry for %s.", what);
                return 0;
        }

        r = unit_name_from_path(what, ".swap", &name);
        if (r < 0)
                return log_error_errno(r, "Failed to generate unit name: %m");

        unit = strjoin(arg_dest, "/", name);
        if (!unit)
                return log_oom();

        f = fopen(unit, "wxe");
        if (!f)
                return log_error_errno(errno,
                                       errno == EEXIST ?
                                       "Failed to create swap unit file %s, as it already exists. Duplicate entry in /etc/fstab?" :
                                       "Failed to create unit file %s: %m",
                                       unit);

        fputs_unlocked("# Automatically generated by systemd-fstab-generator\n\n"
                       "[Unit]\n"
                       "SourcePath=/etc/fstab\n"
                       "Documentation=man:fstab(5) man:systemd-fstab-generator(8)\n\n"
                       "[Swap]\n", f);

        r = write_what(f, what);
        if (r < 0)
                return r;

        r = write_options(f, me->mnt_opts);
        if (r < 0)
                return r;

        r = fflush_and_check(f);
        if (r < 0)
                return log_error_errno(r, "Failed to write unit file %s: %m", unit);

        /* use what as where, to have a nicer error message */
        r = generator_write_timeouts(arg_dest, what, what, me->mnt_opts, NULL);
        if (r < 0)
                return r;

        if (!noauto) {
                r = generator_add_symlink(arg_dest, SPECIAL_SWAP_TARGET,
                                          nofail ? "wants" : "requires", name);
                if (r < 0)
                        return r;
        }

        return 0;
}
コード例 #27
0
ファイル: syslogex.c プロジェクト: Oliviers-OSS/dbgflags
static void
__vsyslogex_chk(int pri, int flag, pid_t cpid, pid_t ctid, const char *fmt, va_list ap) {
    struct tm now_tm;
    time_t now;
    int fd;
    FILE *f;
    char *buf = 0;
    size_t bufsize = 0;
    size_t prioff, msgoff;
#ifndef NO_SIGPIPE
    struct sigaction action, oldaction;
    int sigpipe;
#endif
    int saved_errno = errno;
    char failbuf[3 * sizeof (pid_t) + sizeof "out of memory []"];
    const int LogMask = setlogmask(0);

#ifdef _DEBUGFLAGS_H_
    {
        static unsigned int registered = 0;
        if (unlikely(0 == registered)) {
            registered = 1; /* dirty work around to avoid deadlock: syslogex->register->syslogex */
            registered = (registerLibraryDebugFlags(&debugFlags) == EXIT_SUCCESS);
        }
    }
#endif /*_DEBUGFLAGS_H_*/

#define INTERNALLOG LOG_ERR|LOG_CONS|LOG_PERROR|LOG_PID
    /* Check for invalid bits. */
    if (unlikely(pri & ~(LOG_PRIMASK | LOG_FACMASK))) {
        /*syslog(INTERNALLOG,
               "syslog: unknown facility/priority: %x", pri);*/
        WARNING_MSG("unknown facility/priority: %x", pri);
        pri &= LOG_PRIMASK | LOG_FACMASK;
    }

    /* Check priority against setlogmask values. */
    if (unlikely((LOG_MASK(LOG_PRI(pri)) & LogMask) == 0))
        return;

    /* Set default facility if none specified. */
    if (unlikely((pri & LOG_FACMASK) == 0))
        pri |= LogFacility;

    /* Build the message in a memory-buffer stream.  */
    f = open_memstream(&buf, &bufsize);
    if (unlikely(f == NULL)) {
        /* We cannot get a stream.  There is not much we can do but
           emitting an error messages with the Process ID.  */
        char numbuf[3 * sizeof (pid_t)];
        char *nump;
        char *endp = __stpcpy(failbuf, "out of memory [");
        pid_t pid = getpid();

        nump = numbuf + sizeof (numbuf);
        /* The PID can never be zero.  */
        do {
            *--nump = '0' + pid % 10;
        } while ((pid /= 10) != 0);

        endp = mempcpy((void*) endp, (const void*) nump, (size_t) ((numbuf + sizeof (numbuf)) - nump));
        *endp++ = ']';
        *endp = '\0';
        buf = failbuf;
        bufsize = endp - failbuf;
        msgoff = 0;
    } else {
        __fsetlocking(f, FSETLOCKING_BYCALLER);
        prioff = fprintf(f, "<%d>", pri);
        (void) time(&now);
        f->_IO_write_ptr += strftime(f->_IO_write_ptr,
                f->_IO_write_end - f->_IO_write_ptr,
                "%h %e %T ",
                localtime_r(&now, &now_tm));
        /*f->_IO_write_ptr += strftime_l (f->_IO_write_ptr,
                                          f->_IO_write_end - f->_IO_write_ptr,
                                          "%h %e %T ",
                                          localtime_r (&now, &now_tm));*/
        msgoff = ftell(f);
        if (LogTag == NULL)
            LogTag = __progname;
        if (LogTag != NULL)
            fputs_unlocked(LogTag, f);
        if (LogStat & LOG_PID) {
            const pid_t pid = ((0 == cpid) ? getpid() : cpid);
            if (LogStat & LOG_TID) {
                const pid_t tid = ((0 == ctid) ? gettid() : ctid);
                fprintf(f, "[%d:%d]", (int) pid, (int) tid);
            } else {
                fprintf(f, "[%d]", (int) pid);
            }
        }

        if (LogStat & LOG_RDTSC) {
            const unsigned long long int t = rdtsc();
            fprintf(f, "(%llu)", t);
        } /* (LogStat & LOG_RDTSC) */

        if (LogStat & LOG_CLOCK) {
            #if HAVE_CLOCK_GETTIME
                struct timespec timeStamp;
                if (clock_gettime(CLOCK_MONOTONIC,&timeStamp) == 0) {
                    fprintf(f,"(%lu.%.9d)",timeStamp.tv_sec,timeStamp.tv_nsec);
                } else {
                    const int error = errno;
                    ERROR_MSG("clock_gettime CLOCK_MONOTONIC error %d (%m)",error);
            }
            #else
                static unsigned int alreadyPrinted = 0;
                if (unlikely(0 == alreadyPrinted)) {
                    ERROR_MSG("clock_gettime  not available on this system");
                    alreadyPrinted = 1;
                }
            #endif
        }  /* (LogStat & LOG_CLOCK) */

        if (LogStat & LOG_LEVEL) {
            switch (LOG_PRI(pri)) {
                case LOG_EMERG:
                    fprintf(f, "[EMERG]");
                    break;
                case LOG_ALERT:
                    fprintf(f, "[ALERT]");
                    break;
                case LOG_CRIT:
                    fprintf(f, "[CRIT]");
                    break;
                case LOG_ERR:
                    fprintf(f, "[ERROR]");
                    break;
                case LOG_WARNING:
                    fprintf(f, "[WARNING]");
                    break;
                case LOG_NOTICE:
                    fprintf(f, "[NOTICE]");
                    break;
                case LOG_INFO:
                    fprintf(f, "[INFO]");
                    break;
                case LOG_DEBUG:
                    fprintf(f, "[DEBUG]");
                    break;
            } /* switch(LOG_PRI(pri))*/
        } /* (LogStat & LOG_LEVEL) */

        if (LogTag != NULL) {
            putc_unlocked(':', f);
            putc_unlocked(' ', f);
        }

        /* Restore errno for %m format.  */
        __set_errno(saved_errno);

        /* We have the header.  Print the user's format into the
         buffer.  */
        if (flag == -1) {
            vfprintf(f, fmt, ap);
        } else {
            __vfprintf_chk(f, flag, fmt, ap);
        }

        /* Close the memory stream; this will finalize the data
           into a malloc'd buffer in BUF.  */
        fclose(f);
    }

    /* Output to stderr if requested. */
    if (LogStat & LOG_PERROR) {
        struct iovec iov[2];
        register struct iovec *v = iov;

        v->iov_base = buf + msgoff;
        v->iov_len = bufsize - msgoff;
        /* Append a newline if necessary.  */
        if (buf[bufsize - 1] != '\n') {
            ++v;
            v->iov_base = (char *) "\n";
            v->iov_len = 1;
        }

        pthread_cleanup_push(free, buf == failbuf ? NULL : buf);

        /* writev is a cancellation point.  */
        (void) writev(STDERR_FILENO, iov, v - iov + 1);

        pthread_cleanup_pop(0);
    }

    /* Prepare for multiple users.  We have to take care: open and
  write are cancellation points.  */
    struct cleanup_arg clarg;
    clarg.buf = buf;
    clarg.oldaction = NULL;
    pthread_cleanup_push(cancel_handler, &clarg);
    pthread_mutex_lock(&syslogex_lock);

#ifndef NO_SIGPIPE
    /* Prepare for a broken connection.  */
    memset(&action, 0, sizeof (action));
    action.sa_handler = sigpipe_handler;
    sigemptyset(&action.sa_mask);
    sigpipe = __sigaction(SIGPIPE, &action, &oldaction);
    if (sigpipe == 0)
        clarg.oldaction = &oldaction;
#endif

    /* Get connected, output the message to the local logger. */
    if (!connected) {
        openlog_internal(LogTag, LogStat | LOG_NDELAY, 0);
    }

    /* If we have a SOCK_STREAM connection, also send ASCII NUL as
  a record terminator.  */
    if (LogType == SOCK_STREAM) {
        ++bufsize;
    }

    if (!connected || __send(LogFile, buf, bufsize, send_flags) < 0) {
        if (connected) {
            /* Try to reopen the syslog connection.  Maybe it went
          down.  */
            closelog_internal();
            openlog_internal(LogTag, LogStat | LOG_NDELAY, 0);
        }

        if (!connected || __send(LogFile, buf, bufsize, send_flags) < 0) {
            closelog_internal(); /* attempt re-open next time */
            /*
             * Output the message to the console; don't worry
             * about blocking, if console blocks everything will.
             * Make sure the error reported is the one from the
             * syslogd failure.
             */
            if (LogStat & LOG_CONS &&
                    (fd = __open(_PATH_CONSOLE, O_WRONLY | O_NOCTTY, 0)) >= 0) {
                dprintf(fd, "%s\r\n", buf + msgoff);
                (void) __close(fd);
            }
        }
    }

#ifndef NO_SIGPIPE
    if (sigpipe == 0)
        __sigaction(SIGPIPE, &oldaction, (struct sigaction *) NULL);
#endif

    /* End of critical section.  */
    pthread_cleanup_pop(0);
    pthread_mutex_unlock(&syslogex_lock);

    if (buf != failbuf) {
        free(buf);
    }
}
コード例 #28
0
ファイル: fputs.c プロジェクト: VargMon/bionic
#include <stdio.h>
#include <string.h>
#include "un-namespace.h"
#include "fvwrite.h"
#include "libc_private.h"
#include "local.h"

/*
 * Write the given string to the given file.
 */
int
fputs(const char * __restrict s, FILE * __restrict fp)
{
	int retval;
	FLOCKFILE(fp);
	retval = fputs_unlocked(s, fp);
	FUNLOCKFILE(fp);
	return (retval);
}

int
fputs_unlocked(const char * __restrict s, FILE * __restrict fp)
{
	struct __suio uio;
	struct __siov iov;

	iov.iov_base = (void *)s;
	iov.iov_len = uio.uio_resid = strlen(s);
	uio.uio_iov = &iov;
	uio.uio_iovcnt = 1;
	ORIENT(fp, -1);
コード例 #29
0
ファイル: fputs.c プロジェクト: dennis95/dennix
/* Copyright (c) 2016, Dennis Wölfing
 *
 * Permission to use, copy, modify, and/or distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

/* libc/src/stdio/fputs.c
 * Puts a string into a file.
 */

#include <stdio.h>

int fputs(const char* restrict s, FILE* restrict file) {
    flockfile(file);
    int result = fputs_unlocked(s, file);
    funlockfile(file);
    return result;
}
コード例 #30
0
ファイル: fedora2_true.c プロジェクト: CoolOppo/boomerang
// address: 80498b0
void proc5(char *param1, FILE *param2, char param3[], char param4[], char param5[], __size32 *param6) {
    __size32 eax; 		// r24
    __size32 ebx; 		// r27

    eax = *param6;
    if (eax != 0) {
        do {
            eax = *(param6 + 4);
        } while (eax != 0);
    }
    if (param3 == 0) {
        fprintf(param2, "%s %s\n", param4, param5);
    } else {
        fprintf(param2, "%s (%s) %s\n", param3, param4, param5);
    }
    switch(ebx) {
    case 0:
    case 1:
L16:
L15:
        dcgettext(0, param1, 5);
        vfprintf();
        eax = *(param2 + 20);
        if (eax < *(param2 + 24)) {
            *(__size8*)eax = 10;
            *(__size32*)(param2 + 20)++;
L9:
            eax = *0x804b7d0;
            fputs_unlocked(eax, param2);
            eax = *(param2 + 20);
            if (eax < *(param2 + 24)) {
                *(__size8*)eax = 10;
                *(__size32*)(param2 + 20)++;
L4:
                dcgettext(0, "This is free software; see the source for copying conditions.  There is NO\nwarranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n", 5);
                fputs_unlocked(eax, param2);
                return;
            }
            __overflow();
            goto L4;
        }
        __overflow();
        goto L9;
    case 2:
        goto L15;
    case 3:
        goto L16;
    case 4:
        goto L16;
    case 5:
        goto L16;
    case 6:
        goto L15;
    case 7:
        goto L15;
    case 8:
        goto L16;
    case 9:
        goto L16;
    }
    abort();
    return;
}