示例#1
0
/* Given UNAME, set the corresponding UID and return 1, or else, return 0.  */
int
uname_to_uid (char const *uname, uid_t *uidp)
{
  struct passwd *passwd;

  if (cached_no_such_uname
      && strcmp (uname, cached_no_such_uname) == 0)
    return 0;

  if (!cached_uname
      || uname[0] != cached_uname[0]
      || strcmp (uname, cached_uname) != 0)
    {
      passwd = getpwnam (uname);
      if (passwd)
	{
	  cached_uid = passwd->pw_uid;
	  assign_string (&cached_uname, passwd->pw_name);
	}
      else
	{
	  assign_string (&cached_no_such_uname, uname);
	  return 0;
	}
    }
  *uidp = cached_uid;
  return 1;
}
示例#2
0
/* Given GNAME, set the corresponding GID and return 1, or else, return 0.  */
int
gname_to_gid (char const *gname, gid_t *gidp)
{
  struct group *group;

  if (cached_no_such_gname
      && strcmp (gname, cached_no_such_gname) == 0)
    return 0;

  if (!cached_gname
      || gname[0] != cached_gname[0]
      || strcmp (gname, cached_gname) != 0)
    {
      group = getgrnam (gname);
      if (group)
	{
	  cached_gid = group->gr_gid;
	  assign_string (&cached_gname, gname);
	}
      else
	{
	  assign_string (&cached_no_such_gname, gname);
	  return 0;
	}
    }
  *gidp = cached_gid;
  return 1;
}
示例#3
0
文件: misc.c 项目: Happuri/various
/* Check if FILE_NAME already exists and make a backup of it right now.
   Return success (nonzero) only if the backup is either unneeded, or
   successful.  For now, directories are considered to never need
   backup.  If THIS_IS_THE_ARCHIVE is nonzero, this is the archive and
   so, we do not have to backup block or character devices, nor remote
   entities.  */
bool
maybe_backup_file (const char *file_name, bool this_is_the_archive)
{
  struct stat file_stat;

  assign_string (&before_backup_name, file_name);

  /* A run situation may exist between Emacs or other GNU programs trying to
     make a backup for the same file simultaneously.  If theoretically
     possible, real problems are unlikely.  Doing any better would require a
     convention, GNU-wide, for all programs doing backups.  */

  assign_string (&after_backup_name, 0);

  /* Check if we really need to backup the file.  */

  if (this_is_the_archive && _remdev (file_name))
    return true;

  if (deref_stat (file_name, &file_stat) != 0)
    {
      if (errno == ENOENT)
	return true;

      stat_error (file_name);
      return false;
    }

  if (S_ISDIR (file_stat.st_mode))
    return true;

  if (this_is_the_archive
      && (S_ISBLK (file_stat.st_mode) || S_ISCHR (file_stat.st_mode)))
    return true;

  after_backup_name = find_backup_file_name (file_name, backup_type);
  if (! after_backup_name)
    xalloc_die ();

  if (renameat (chdir_fd, before_backup_name, chdir_fd, after_backup_name)
      == 0)
    {
      if (verbose_option)
	fprintf (stdlis, _("Renaming %s to %s\n"),
		 quote_n (0, before_backup_name),
		 quote_n (1, after_backup_name));
      return true;
    }
  else
    {
      /* The backup operation failed.  */
      int e = errno;
      ERROR ((0, e, _("%s: Cannot rename to %s"),
	      quotearg_colon (before_backup_name),
	      quote_n (1, after_backup_name)));
      assign_string (&after_backup_name, 0);
      return false;
    }
}
示例#4
0
int
maybe_backup_file (const char *path, int archive)
{
  struct L_STAT file_stat;

  /* Check if we really need to backup the file.  */

  if (archive && _remdev (path))
    return 1;

  if (L_STAT (path, &file_stat))
    {
      if (errno == ENOENT)
	return 1;

      ERROR ((0, errno, "%s", path));
      return 0;
    }

  if (S_ISDIR (file_stat.st_mode))
    return 1;

#ifdef S_ISBLK
  if (archive && S_ISBLK (file_stat.st_mode))
    return 1;
#endif

#ifdef S_ISCHR
  if (archive && S_ISCHR (file_stat.st_mode))
    return 1;
#endif

  assign_string (&before_backup_name, path);

  /* A run situation may exist between Emacs or other GNU programs trying to
     make a backup for the same file simultaneously.  If theoretically
     possible, real problems are unlikely.  Doing any better would require a
     convention, GNU-wide, for all programs doing backups.  */

  assign_string (&after_backup_name, NULL);
  after_backup_name = find_backup_file_name (path);
  if (after_backup_name == NULL)
    FATAL_ERROR ((0, 0, "Virtual memory exhausted"));

  if (rename (before_backup_name, after_backup_name) == 0)
    {
      if (verbose_option)
	fprintf (stdlis, _("Renaming previous `%s' to `%s'\n"),
		 before_backup_name, after_backup_name);
      return 1;
    }

  /* The backup operation failed.  */

  ERROR ((0, errno, _("%s: Cannot rename for backup"), before_backup_name));
  assign_string (&after_backup_name, NULL);
  return 0;
}
示例#5
0
static int
Transfer_setattr(twopence_Transfer *self, char *name, PyObject *v)
{
	if (!strcmp(name, "remotefile")) {
		char *s;

		if (!PyString_Check(v) || (s = PyString_AsString(v)) == NULL)
			goto bad_attr;
		assign_string(&self->remote_filename, s);
		return 0;
	}
	if (!strcmp(name, "localfile")) {
		char *s;

		if (!PyString_Check(v) || (s = PyString_AsString(v)) == NULL)
			goto bad_attr;
		assign_string(&self->local_filename, s);
		return 0;
	}
	if (!strcmp(name, "user")) {
		char *s;

		if (!PyString_Check(v) || (s = PyString_AsString(v)) == NULL)
			goto bad_attr;
		assign_string(&self->user, s);
		return 0;
	}
	if (!strcmp(name, "permissions")) {
		if (!PyInt_Check(v))
			goto bad_attr;
		self->permissions = PyInt_AsLong(v);
		return 0;
	}
	if (!strcmp(name, "timeout")) {
		if (!PyInt_Check(v))
			goto bad_attr;
		self->timeout = PyInt_AsLong(v);
		return 0;
	}
	if (!strcmp(name, "data")) {
		if (v != Py_None && !PyByteArray_Check(v))
			goto bad_attr;
		assign_object(&self->buffer, v);
		return 0;
	}

	(void) PyErr_Format(PyExc_AttributeError, "Unknown attribute: %s", name);
	return -1;

bad_attr:
	(void) PyErr_Format(PyExc_AttributeError, "Incompatible value for attribute: %s", name);
	return -1;

}
示例#6
0
/* Given UID, find the corresponding UNAME.  */
void
uid_to_uname (uid_t uid, char **uname)
{
  struct passwd *passwd;

  if (uid != 0 && uid == cached_no_such_uid)
    {
      *uname = xstrdup ("");
      return;
    }

  if (!cached_uname || uid != cached_uid)
    {
      passwd = getpwuid (uid);
      if (passwd)
	{
	  cached_uid = uid;
	  assign_string (&cached_uname, passwd->pw_name);
	}
      else
	{
	  cached_no_such_uid = uid;
	  *uname = xstrdup ("");
	  return;
	}
    }
  *uname = xstrdup (cached_uname);
}
示例#7
0
/* Check if the next block contains a volume label and if this matches
   the one given in the command line */
static void match_volume_label(shfs_arch_t *arch)
{
  if (!volume_label)
  {
    union block *label = shfs_arch_buffer_next(arch);

    if (!label)
      return;
    if (label->header.typeflag == GNUTYPE_VOLHDR)
    {
      if (memchr (label->header.name, '\0', sizeof label->header.name))
        assign_string (&volume_label, label->header.name);
      else
      {
        volume_label = malloc (sizeof (label->header.name) + 1);
        memcpy (volume_label, label->header.name,
            sizeof (label->header.name));
        volume_label[sizeof (label->header.name)] = 0;
      }
    }
    else if (label->header.typeflag == XGLTYPE)
    {
      /* .. */
    }
  }

  if (!volume_label)
    return;

  if (!check_label_pattern (volume_label))
    return;
}
示例#8
0
文件: ggsock.c 项目: INNOAUS/gsl
static int
store_module_error (THREAD       *gsl_thread,
                    SOCK_CONTEXT *context,
                    RESULT_NODE  *error,
                    const char   *error_msg,
                          char   **error_text)
{
    GGCODE_TCB
        *gsl_tcb = gsl_thread-> tcb;
    VALUE
        value;

    if (error_msg)
      {
        if (! context)
            context = get_class_item (gsl_thread, SOCK_NAME);
        mem_free (context-> error_msg);
        context-> error_msg = memt_strdup (NULL, error_msg);

        if (error)
          {
            init_value (& value);
            assign_string (& value, context-> error_msg);
            if (! store_symbol_definition (& gsl_tcb-> scope_stack,
                                           gsl_tcb-> gsl-> ignorecase,
                                           error,
                                           &value,
                                           error_text))
                return -1;
          }
      }
    return 0;
}
示例#9
0
Exec_stat MCVariableValue::store(MCExecPoint& ep)
{
	switch(ep . getformat())
	{
	case VF_UNDEFINED:
		clear();
	break;

	case VF_STRING:
		assign_string(ep . getsvalue());
	break;

	case VF_NUMBER:
		assign_real(ep . getnvalue());
	break;

	case VF_BOTH:
		assign_both(ep . getsvalue(), ep . getnvalue());
	break;

	case VF_ARRAY:
		// MW-2008-08-30: [[ Bug ]] Doing put tArray[x] into tArray causes badness since 'assign'
		//   first deletes the current value then copies.
		if (!is_array() || ep . getdeletearray())
			assign(*(ep . getarray()));
		else
		{
			MCVariableValue t_temp(*(ep . getarray()));
			exchange(t_temp);
		}
	break;
	}

	return ES_NORMAL;
}
示例#10
0
char *
xheader_xhdr_name (struct tar_stat_info *st)
{
  if (!exthdr_name)
    assign_string (&exthdr_name, "%d/PaxHeaders.%p/%f");
  return xheader_format_name (st, exthdr_name, 0);
}
示例#11
0
/* Given GID, find the corresponding GNAME.  */
void
gid_to_gname (gid_t gid, char **gname)
{
  struct group *group;

  if (gid != 0 && gid == cached_no_such_gid)
    {
      *gname = xstrdup ("");
      return;
    }

  if (!cached_gname || gid != cached_gid)
    {
      group = getgrgid (gid);
      if (group)
	{
	  cached_gid = gid;
	  assign_string (&cached_gname, group->gr_name);
	}
      else
	{
	  cached_no_such_gid = gid;
	  *gname = xstrdup ("");
	  return;
	}
    }
  *gname = xstrdup (cached_gname);
}
示例#12
0
int main(void) {

  int
    str1_cnt = 0,
    str2_cnt = 0;
  char 
    c,
    flip_flop = 0,
    *str1 = NULL,
    *str2 = NULL;

  while((c = getchar()) != '\n') {

    switch(flip_flop) {

    case 0:
      if(assign_string(&str2, c, ++str2_cnt) < 0)
	goto bad_exit;
      break;
      
    case 1:
      if(assign_string(&str1, c, ++str1_cnt) < 0)
	goto bad_exit;
      break;
      
    default:
      /* ? */
      break;
    }
    flip_flop = !flip_flop;
  }
  
  /* good exit */
  printf("String 1: %s\n", str1);
  printf("String 2: %s\n", str2);
  free(str1);
  free(str2);
  return 0;
  
 bad_exit:
  printf("ERROR: Failed to allocate memory!\n");
  free(str1);
  free(str2);
  return -1;
}
示例#13
0
static void
xheader_set_keyword_equal (char *kw, char *eq)
{
  bool global = true;
  char *p = eq;

  if (eq[-1] == ':')
    {
      p--;
      global = false;
    }

  while (p > kw && isspace ((unsigned char) *p))
    p--;

  *p = 0;

  for (p = eq + 1; *p && isspace ((unsigned char) *p); p++)
    ;

  if (strcmp (kw, "delete") == 0)
    {
      if (xheader_protected_pattern_p (p))
	USAGE_ERROR ((0, 0, _("Pattern %s cannot be used"), quote (p)));
      xheader_list_append (&keyword_pattern_list, p, NULL);
    }
  else if (strcmp (kw, "exthdr.name") == 0)
    assign_string (&exthdr_name, p);
  else if (strcmp (kw, "globexthdr.name") == 0)
    assign_string (&globexthdr_name, p);
  else if (strcmp (kw, "exthdr.mtime") == 0)
    assign_time_option (&exthdr_mtime_option, &exthdr_mtime, p);
  else if (strcmp (kw, "globexthdr.mtime") == 0)
    assign_time_option (&globexthdr_mtime_option, &globexthdr_mtime, p);
  else
    {
      if (xheader_protected_keyword_p (kw))
	USAGE_ERROR ((0, 0, _("Keyword %s cannot be overridden"), kw));
      if (global)
	xheader_list_append (&keyword_global_override_list, kw, p);
      else
	xheader_list_append (&keyword_override_list, kw, p);
    }
}
void note_attach ( Creature *ch, int type )
{
	NOTE_DATA *pnote;

	if ( ch->pnote != NULL )
	{ return; }

	pnote = new_note();

	pnote->next		= NULL;
	pnote->sender	= assign_string ( ch->name );
	pnote->date		= assign_string ( "" );
	pnote->to_list	= assign_string ( "" );
	pnote->subject	= assign_string ( "" );
	pnote->text		= assign_string ( "" );
	pnote->type		= type;
	ch->pnote		= pnote;
	return;
}
示例#15
0
bool MCVariableValue::assign_both(const MCString& s, real64_t n)
{
	if (!assign_string(s))
		return false;

	set_type(VF_BOTH);
	strnum . nvalue = n;

	return true;
}
示例#16
0
文件: ggsock.c 项目: INNOAUS/gsl
static void
reply_readh_result (byte *body, char *error_msg)
{
    struct_smtsock_readh_reply
        *readh_reply;
    GGCODE_TCB
        *gsl_tcb = tcb-> gsl_thread-> tcb;
    VALUE
        value;
    char
        *error_text;

    /*  Pick up read value  */
    get_smtsock_readh_reply (body, & readh_reply);
    init_value (& value);
    if (readh_reply-> size > 0)
      {
        assign_string (& value, memt_alloc (NULL, readh_reply-> size + 1));
        memcpy (value. s, readh_reply-> data, readh_reply-> size);
        value. s [readh_reply-> size] = '\0';
      }
    /*  Store the value  */
    if (! store_symbol_definition (& gsl_tcb-> scope_stack,
                                   gsl_tcb-> gsl-> ignorecase,
                                   tcb-> buffer,
                                   &value,
                                   &error_text))
      {
        lsend_ggcode_call_error (& tcb-> gsl_thread-> queue-> qid, NULL,
                                 NULL, NULL, NULL, 0,
                                 NULL, 0,
                                 error_text);
        return;
      }
    destroy_value (& value);

    /*  Build return value  */
    assign_number (& tcb-> result-> value, readh_reply-> size);

    free_smtsock_readh_reply (& readh_reply);

    if (store_sock_error (tcb-> sock_handle,
                          tcb-> gsl_thread,
                          tcb-> context,
                          tcb-> error,
                          error_msg,
                          &error_text))
        lsend_ggcode_call_error (& tcb-> gsl_thread-> queue-> qid, NULL,
                                 NULL, NULL, NULL, 0,
                                 NULL, 0,
                                 error_text);
    else
        lsend_ggcode_call_ok (& tcb-> gsl_thread-> queue-> qid, NULL,
                              NULL, NULL, NULL, 0);
}
示例#17
0
bool
transform_name_fp (char **pinput, int flags,
		   char *(*fun)(char *, void *), void *dat)
{
    char *str;
    bool ret = _transform_name_to_obstack (flags, *pinput, &str);
    if (ret)
      {
	assign_string (pinput, fun ? fun (str, dat) : str);
	obstack_free (&stk, str);
      }
    else if (fun)
      {
	*pinput = NULL;
	assign_string (pinput, fun (str, dat));
	free (str);
	ret = true;
      }
    return ret;
}
int main(int argc, char *argv[])
{
  //read_input();
  assign_string();
  
  int num[2][2];
  num[0][1] = 1;

  return 0;

}
示例#19
0
/* Try to restore the recently backed up file to its original name.
   This is usually only needed after a failed extraction.  */
void
undo_last_backup (void)
{
  if (after_backup_name)
    {
      if (renameat (chdir_fd, after_backup_name, chdir_fd, before_backup_name)
	  != 0)
	{
	}
      assign_string (&after_backup_name, 0);
    }
}
示例#20
0
static int
Command_setattr(twopence_Command *self, char *name, PyObject *v)
{
	if (!strcmp(name, "stdout")) {
		if (v != Py_None && !PyByteArray_Check(v))
			goto bad_attr;
		assign_object(&self->stdout, v);
		return 0;
	}
	if (!strcmp(name, "stderr")) {
		if (v != Py_None && !PyByteArray_Check(v))
			goto bad_attr;
		assign_object(&self->stderr, v);
		return 0;
	}
	if (!strcmp(name, "user")) {
		char *s;

		if (!PyString_Check(v) || (s = PyString_AsString(v)) == NULL)
			goto bad_attr;
		assign_string(&self->user, s);
		return 0;
	}
	if (!strcmp(name, "timeout")) {
		if (PyInt_Check(v))
			self->timeout = PyInt_AsLong(v);
		else if (PyLong_Check(v))
			self->timeout = PyLong_AsLongLong(v);
		else
			goto bad_attr;
		return 0;
	}
	if (!strcmp(name, "quiet")) {
		self->quiet = !!(PyObject_IsTrue(v));
		return 0;
	}
	if (!strcmp(name, "useTty")) {
		self->useTty = !!(PyObject_IsTrue(v));
		return 0;
	}
	if (!strcmp(name, "background")) {
		self->background = !!(PyObject_IsTrue(v));
		return 0;
	}

	(void) PyErr_Format(PyExc_AttributeError, "Unknown attribute: %s", name);
	return -1;

bad_attr:
	(void) PyErr_Format(PyExc_AttributeError, "Incompatible value for attribute: %s", name);
	return -1;

}
示例#21
0
static void
assign_time_option (char **sval, time_t *tval, const char *input)
{
  char *p;
  struct timespec t = decode_timespec (input, &p, false);
  if (! valid_timespec (t) || *p)
    ERROR ((0, 0, _("Time stamp is out of allowed range")));
  else
    {
      *tval = t.tv_sec;
      assign_string (sval, input);
    }
}
示例#22
0
文件: opts.c 项目: liaonau/chooser
inline static void loadconf()
{
    const gchar* const *config_dirs = g_get_system_config_dirs();
    GPtrArray          *ptr_paths   = g_ptr_array_new();
    g_ptr_array_add(ptr_paths, g_build_filename(g_get_user_config_dir(), APPNAME, "/", NULL));
    for(; *config_dirs; config_dirs++)
        g_ptr_array_add(ptr_paths, g_build_filename(*config_dirs, APPNAME, "/", NULL));
    gchar** paths = (gchar**)g_ptr_array_free(ptr_paths, FALSE);

    GError* error = NULL;
    GKeyFile* key_file = g_key_file_new();
    gchar* fullpath = NULL;
    gboolean can_be_loaded = g_key_file_load_from_dirs(key_file, "config", (const gchar**)paths, &fullpath, G_KEY_FILE_NONE, &error);
    if (!can_be_loaded)
    {
        warn("%s\n", error->message);
        g_error_free(error);
    }
    else
    {

        assign_boolean(key_file, &conf.onecolumn,  "onecolumn" );
        assign_boolean(key_file, &conf.checkbox,   "checkbox"  );
        assign_boolean(key_file, &conf.numbers,    "numbers"   );
        assign_boolean(key_file, &conf.underline,  "underline" );
        assign_boolean(key_file, &conf.color,      "color"     );
        assign_boolean(key_file, &conf.radiobox,   "radiobox"  );
        assign_boolean(key_file, &conf.initial,    "initial"   );
        assign_boolean(key_file, &conf.whitelines, "whitelines");
        assign_boolean(key_file, &conf.fullattr,   "fullattr"  );
        assign_string (key_file, &conf.foreground, "foreground");
        assign_string (key_file, &conf.background, "background");
    }

    g_key_file_free(key_file);
    g_strfreev(paths);
    g_free(fullpath);
}
示例#23
0
// This is a support method for the V1 externals API. It allows the buffer of
// a value to hold a temporary stringified value with custom number formatting.
// Note that the stored string has a NUL included, to help with passing around.
bool MCVariableValue::assign_custom_both(const char *s, real64_t n)
{
	// Assign the string, but with the NUL included.
	if (!assign_string(MCString(s, strlen(s) + 1)))
		return false;

	// Make sure the extra NUL isn't included in the string value's length
	strnum . svalue . length -= 1;

	set_type(VF_NUMBER);
	strnum . nvalue = n;

	return true;
}
示例#24
0
void
undo_last_backup (void)
{
  if (after_backup_name)
    {
      if (rename (after_backup_name, before_backup_name) != 0)
	ERROR ((0, errno, _("%s: Cannot rename from backup"),
		before_backup_name));
      if (verbose_option)
	fprintf (stdlis, _("Renaming `%s' back to `%s'\n"),
		 after_backup_name, before_backup_name);
      assign_string (&after_backup_name, NULL);
    }
}
示例#25
0
static void
assign_time_option (char **sval, time_t *tval, const char *input)
{
  uintmax_t u;
  char *p;
  time_t t = u = strtoumax (input, &p, 10);
  if (t != u || *p || errno == ERANGE)
    ERROR ((0, 0, _("Time stamp is out of allowed range")));
  else
    {
      *tval = t;
      assign_string (sval, input);
    }
}
示例#26
0
static void
decode_string (char **string, char const *arg)
{
  if (*string)
    {
      free (*string);
      *string = NULL;
    }
  if (!utf8_convert (false, arg, string))
    {
      /* FIXME: report error and act accordingly to --pax invalid=UTF-8 */
      assign_string (string, arg);
    }
}
示例#27
0
void sal_op_set_route(SalOp *op, const char *route){
	char* route_string=(void *)0;
	SalOpBase* op_base = (SalOpBase*)op;
	if (op_base->route_addresses) {
		ms_list_for_each(op_base->route_addresses,(void (*)(void *))sal_address_destroy);
		op_base->route_addresses=ms_list_free(op_base->route_addresses);
	}
	if (route) {
		op_base->route_addresses=ms_list_append(NULL,NULL);
		assign_address((SalAddress**)&(op_base->route_addresses->data),route);
		route_string=sal_address_as_string((SalAddress*)op_base->route_addresses->data); \
	}
	assign_string(&op_base->route,route_string); \
	if(route_string) ms_free(route_string);
}
示例#28
0
/* Mark the archive with volume label STR. */
static void _write_volume_label(shfs_arch_t *arch, const char *str)
{
  union block *label = shfs_arch_buffer_next(arch);

  memset (label, 0, BLOCKSIZE);

  strcpy (label->header.name, str);
  assign_string (&current_stat_info.file_name,
      label->header.name);
  current_stat_info.had_trailing_slash =
    strip_trailing_slashes (current_stat_info.file_name);

  label->header.typeflag = GNUTYPE_VOLHDR;
  TIME_TO_CHARS(arch, arch->start_time.tv_sec, label->header.mtime);
  shfs_arch_finish_header(arch, &current_stat_info, label, -1);
  shfs_arch_set_next_block_after(arch, label);
}
示例#29
0
/* Try to restore the recently backed up file to its original name.
   This is usually only needed after a failed extraction.  */
void
undo_last_backup (void)
{
  if (after_backup_name)
    {
      if (rename (after_backup_name, before_backup_name) != 0)
	{
	  int e = errno;
	  ERROR ((0, e, _("%s: Cannot rename to %s"),
		  quotearg_colon (after_backup_name),
		  quote_n (1, before_backup_name)));
	}
      if (verbose_option)
	fprintf (stdlis, _("Renaming %s back to %s\n"),
		 quote_n (0, after_backup_name),
		 quote_n (1, before_backup_name));
      assign_string (&after_backup_name, 0);
    }
}
示例#30
0
文件: ggsock.c 项目: INNOAUS/gsl
static VALUE * sock_handle_get_attr (void *item, const char *name, Bool ignorecase)
{

    SOCK_HANDLE_ITEM
        *socket = item;
    static VALUE
        value;

    if (! name)
        return NULL;

    init_value (& value);
        
    if (matches (name, "error"))
      {

        if (socket-> error_msg)
            assign_string (& value, socket-> error_msg);
        
      }

    return & value;
        
}