Example #1
0
FILE *my_fdopen(File Filedes, const char *name, int Flags, myf MyFlags)
{
  FILE *fd;
  char type[5];
  DBUG_ENTER("my_fdopen");
  DBUG_PRINT("my",("Fd: %d  Flags: %d  MyFlags: %d",
		   Filedes, Flags, MyFlags));

  make_ftype(type,Flags);
#ifdef _WIN32
  fd= my_win_fdopen(Filedes, type);
#else
  fd= fdopen(Filedes, type);
#endif
  if (!fd)
  {
    set_my_errno(errno);
    if (MyFlags & (MY_FAE | MY_WME))
    {
      char errbuf[MYSYS_STRERROR_SIZE];
      my_error(EE_CANT_OPEN_STREAM, MYF(0),
               my_errno(), my_strerror(errbuf, sizeof(errbuf), my_errno()));
    }
  }
  else
  {
    mysql_mutex_lock(&THR_LOCK_open);
    my_stream_opened++;
    if ((uint) Filedes < (uint) my_file_limit)
    {
      if (my_file_info[Filedes].type != UNOPEN)
      {
        my_file_opened--;		/* File is opened with my_open ! */
      }
      else
      {
        my_file_info[Filedes].name= my_strdup(key_memory_my_file_info,
                                              name,MyFlags);
      }
      my_file_info[Filedes].type = STREAM_BY_FDOPEN;
    }
    mysql_mutex_unlock(&THR_LOCK_open);
  }

  DBUG_PRINT("exit",("stream: 0x%lx", (long) fd));
  DBUG_RETURN(fd);
} /* my_fdopen */
Example #2
0
void display_R(int flag,char *pathname)
{
    int i,j;
    struct stat buf;
    char name[NAME_MAX + 1];
    for(i=0,j=0;i<strlen(pathname);i++)
    {
        if(pathname[i] == '/')
        {
            j = 0;
        }
        else
            name[j++] = pathname[i];
    }
    name[j] = 0;

    if(lstat(pathname,&buf) == -1)
    {
        my_error("stat",__LINE__);
    }

    if(flag == PARAM_NONE)
    {
        if(name[0] != '.')//不显示隐藏文件
        {
            display_single(name);
        }
    }
    else if(flag == PARAM_A)
    {
        display_single(name);
    }
    else if(flag == PARAM_L)
    {
        if(name[0] != '.')
        {
            display_attribute(buf,name);
            printf(" %-s\n",name);
        }
    }
    else if(flag == (PARAM_A | PARAM_L))
    {
        display_attribute(buf,name);
        printf(" %-s\n",name);
    }

}
Example #3
0
integ *mk_integ(
    double (*h)(double parameter,double constant,double x),
    double xlo,
    double xhi,
    double parameter,
    double constant,
    int size
  )
/*
   Returns an it in which
   it->integral[i] = integal_from_xlo_to(x_lo + h*i) of h(parameter,x) dx
                     ------------------------------------------------
                     integal_from_xlo_to_x_hi of h(parameter,x) dx
*/
{
  integ *it = AM_MALLOC(integ);
  dyv *dig = mk_dyv(size);
  int i;
  double sum = 0.0;
  double last_pdf = 0.0;
  double delta = (xhi - xlo) / (size-1);

  if ( h(parameter,constant,xhi) > 1e-6 )
    my_error("Hmm... I was really hoping h(parameter,xhi) == 0");

  dyv_set(dig,0,0.0);

  for ( i = 1 ; i < size ; i++ )
  {
    double x = xlo + i * delta;
    double this_pdf = h(parameter,constant,x);
    if (i == 1) sum += delta * this_pdf;
    else        sum += delta * (this_pdf + last_pdf) / 2.0;
    dyv_set(dig,i,sum);
    last_pdf = this_pdf;  /* added 2/26/97  JGS */
  }

  dyv_scalar_mult(dig,1.0 / sum,dig);

  it -> integral = dig;
  it -> xlo = xlo;
  it -> xhi = xhi;
  it -> parameter = parameter;
  it -> constant = constant;

  return(it);
}
Example #4
0
void create_stats(char *user_id) {
    FILE *file;
    char path[50];

    sprintf(path, "./gameplay/%s_stat.dat", user_id);
    if ( (file = fopen(path, "a+")) == NULL) {
        my_error("Cannont open user stat file");
    } else {
        fprintf(file, "User: %s\n", user_id);
        fprintf(file, "Info: none\n");
        fprintf(file, "Wins: 0\nLoses: 0\n");
        fprintf(file, "Quiet: no\n");
        fprintf(file, "Blocked: none\n");

        fclose(file);
    }
}
Example #5
0
static int
my_getc(void *data)
{
    struct state *s = data;
    int c;

    c = fgetc(input);
    if (c == '.' && s->prev_char == '\n') {
	/* end-of-verb marker in DB */
	c = fgetc(input);	/* skip next newline */
	return EOF;
    }
    if (c == EOF)
	my_error(data, "Unexpected EOF");
    s->prev_char = c;
    return c;
}
Example #6
0
void	load(char *name)
{
  int	len_name;
  char	*new_name;

  len_name = my_strlen(name);
  if (len_name > 1 && (name[len_name - 1] != 's' || name[len_name - 2] != '.'))
    {
      if ((new_name = malloc(sizeof(char) * len_name + 3)) == NULL)
	my_error("Can't perform malloc.\n", 1);
      my_strcpy(new_name, name);
      my_strcat(new_name, ".s");
    }
  else
    new_name = my_strdup(name);
  check_file(new_name);
}
Example #7
0
int getnumber (char* string) {
	int i,answer=0;
	char c,flag=1;
	for (i=0;i<sizeof(string);++i) {
		c=string[i];
		if ((flag==1)&&( (c>'9')||(c<'0') )) {
			my_error ("NOT A NUMBER!\n\0");
		}
		if ( (c>='0')&&(c<='9') ) {
			answer=answer*10+c-'0';
			flag=0;
		}
		if ((flag==0)&&( (c>'9')||(c<'0') ))
			break;
	}
	return answer;
}
Example #8
0
char		*re_alloc(char *str)
{
  char		*str2;
  int		i;

  i = 0;
  if ((str2 = malloc((my_strlen(str) + 2) * sizeof(char))) == NULL)
    my_error("Error with an allocation");
  while (str[i] != '\0')
    {
      str2[i] = str[i];
      i++;
    }
  str2[i + 1] = '\0';
  free(str);
  return (str2);
}
Example #9
0
/* This should be called instead of lgamma on Windows NT platforms.
   The code was taken from Numerical Recipes in C (where it is called
   gammln) , amended to use doubles not floats. 

   N.B. I have added a check to make sure the argument is in the correct
   range.
*/
double am_lgamma(double xx)
{
	double x,y,tmp,ser;
	static double cof[6]={76.18009172947146,-86.50532032941677,
		24.01409824083091,-1.231739572450155,
		0.1208650973866179e-2,-0.5395239384953e-5};
	int j;

	if (xx <= 0.0)
	  my_error("lgamma given a non-positive argument");
	y=x=xx;
	tmp=x+5.5;
	tmp -= (x+0.5)*log(tmp);
	ser=1.000000000190015;
	for (j=0;j<=5;j++) ser += cof[j]/++y;
	return -tmp+log(2.5066282746310005*ser/x);
}
Example #10
0
t_tmp		*new_tmp(void)
{
  t_tmp		*tmp;

  if ((tmp = malloc(sizeof(t_tmp))) == NULL)
    my_error("Can't alloc memory");
  tmp->name = NULL;
  tmp->x = 0;
  tmp->y = 0;
  tmp->z = 0;
  tmp->rot_x = 0;
  tmp->rot_y = 0;
  tmp->rot_z = 0;
  tmp->angle = 0;
  tmp->color = 0x000000;
  return (tmp);
}
Example #11
0
static void	for_fe_cmd (int argc, char **argv, const char *subargs)
{
	char 	*var, *list, *cmds;
	char	*next, *real_list, *x;

	if (!subargs)
		subargs = empty_string;

	if ((my_stricmp(argv[1], "in")) || (argc != 4)) {
		my_error("Usage: /FOR var IN (list) {commands}");
		return;
	}

	var = argv[0];
	list = argv[2];
	cmds = argv[3];

	if (*cmds == '{')
		cmds++;
	if (*list == '(')
		list++;
	x = real_list = expand_alias(list, subargs);
	will_catch_break_exceptions++;
	will_catch_continue_exceptions++;
	while (real_list && *real_list)
	{
		next = next_func_arg(real_list, &real_list);
		add_local_alias(var, next, 0);
		runcmds(cmds, subargs);

		if (break_exception) {
			break_exception = 0;
			break;
		}
		if (continue_exception)
			continue_exception = 0;	/* Dont continue here! */
		if (return_exception)
			break;
		if (system_exception)
			break;
	}
	will_catch_break_exceptions--;
	will_catch_continue_exceptions--;
	new_free(&x);
}
Example #12
0
static void	proc_statm(t_proc *proc, char *path, t_mem *mem)
{
  char		**wordtab;
  int		fd;

  if ((fd = open(path, O_RDONLY)) == -1)
    return ;
  close(fd);
  path = my_strcat(path, "/statm");
  if (!(wordtab = one_line_parsing(path, ' ')))
    my_error("invalid /proc/[pid]/statm");
  proc->virt = (double)atol(wordtab[0]) * getpagesize() / 1024;
  proc->res = (double)atol(wordtab[1]) * getpagesize() / 1024;
  proc->shr = (double)atol(wordtab[2]) * getpagesize() / 1024;
  proc->mem = proc->res / mem->mem * 100;
  free_wordtab(wordtab);
  free(path);
}
Example #13
0
int my_delete(const char *name, myf MyFlags)
{
  int err;
  DBUG_ENTER("my_delete");
  DBUG_PRINT("my",("name %s MyFlags %d", name, MyFlags));

  if ((err = unlink(name)) == -1)
  {
    my_errno=errno;
    if (MyFlags & (MY_FAE+MY_WME))
      my_error(EE_DELETE,MYF(ME_BELL+ME_WAITTANG+(MyFlags & ME_NOINPUT)),
	       name,errno);
  }
  else if ((MyFlags & MY_SYNC_DIR) &&
           my_sync_dir_by_file(name, MyFlags))
    err= -1;
  DBUG_RETURN(err);
} /* my_delete */
Example #14
0
CHARSET_INFO *get_charset_by_name(const char *cs_name, myf flags)
{
  uint cs_number;
  CHARSET_INFO *cs;
  my_pthread_once(&charsets_initialized, init_available_charsets);

  cs_number=get_collation_number(cs_name);
  cs= cs_number ? get_internal_charset(cs_number,flags) : NULL;

  if (!cs && (flags & MY_WME))
  {
    char index_file[FN_REFLEN + sizeof(MY_CHARSET_INDEX)];
    strmov(get_charsets_dir(index_file),MY_CHARSET_INDEX);
    my_error(EE_UNKNOWN_COLLATION, MYF(ME_BELL), cs_name, index_file);
  }

  return cs;
}
Example #15
0
/**
  Delete file which is possibly not closed.

  This function is intended to be used exclusively as a temporal solution
  for Win NT in case when it is needed to delete a not closed file (note
  that the file must be opened everywhere with FILE_SHARE_DELETE mode).
  Deleting not-closed files can not be supported on Win 98|ME (and because
  of that is considered harmful).
  
  The function deletes the file with its preliminary renaming. This is
  because when not-closed share-delete file is deleted it still lives on
  a disk until it will not be closed everwhere. This may conflict with an
  attempt to create a new file with the same name. The deleted file is
  renamed to <name>.<num>.deleted where <name> - the initial name of the
  file, <num> - a hexadecimal number chosen to make the temporal name to
  be unique.

  @param the name of the being deleted file
  @param the flags instructing how to react on an error internally in
         the function

  @note The per-thread @c my_errno holds additional info for a caller to
        decide how critical the error can be.

  @retval
    0	ok
  @retval
    1   error


*/
int nt_share_delete(const char *name, myf MyFlags)
{
  char buf[MAX_PATH + 20];
  ulong cnt;
  DBUG_ENTER("nt_share_delete");
  DBUG_PRINT("my",("name %s MyFlags %d", name, MyFlags));

  for (cnt= GetTickCount(); cnt; cnt--)
  {
    errno= 0;
    sprintf(buf, "%s.%08X.deleted", name, cnt);
    if (MoveFile(name, buf))
      break;

    if ((errno= GetLastError()) == ERROR_ALREADY_EXISTS)
      continue;

    /* This happened during tests with MERGE tables. */
    if (errno == ERROR_ACCESS_DENIED)
      continue;

    DBUG_PRINT("warning", ("Failed to rename %s to %s, errno: %d",
                           name, buf, errno));
    break;
  }
  
  if (errno == ERROR_FILE_NOT_FOUND)
  {
       my_errno= ENOENT;    // marking, that `name' doesn't exist 
  }
  else if (errno == 0)
  {
       if (DeleteFile(buf))
            DBUG_RETURN(0);
       else if ((my_errno= GetLastError()) == 0)
            my_errno= ENOENT; // marking, that `buf' doesn't exist
  } else
       my_errno= errno;
  
  if (MyFlags & (MY_FAE+MY_WME))
       my_error(EE_DELETE, MYF(ME_BELL + ME_WAITTANG + (MyFlags & ME_NOINPUT)),
                name, my_errno);
  DBUG_RETURN(-1);
}
Example #16
0
int	my_cat(char *filename, t_opt opts)
{
  int	nl;
  int	nb;
  int	file;
  char	str[BUFF_SIZE + 1];

  file = open(filename, O_RDONLY, BUFF_SIZE);
  if (file == -1)
    return (my_error(filename));
  my_init(&nl, &nb);
  while (read(file, &str, BUFF_SIZE) > 0)
    {
      str[BUFF_SIZE] = 0;
      exec_cat(str, opts, &nb, &nl);
    }
  close(file);
  return (0);
}
Example #17
0
int my_symlink(const char *content, const char *linkname, myf MyFlags)
{
#ifndef HAVE_READLINK
  return 0;
#else
  int result;
  DBUG_ENTER("my_symlink");

  result= 0;
  if (symlink(content, linkname))
  {
    result= -1;
    my_errno=errno;
    if (MyFlags & MY_WME)
      my_error(EE_CANT_SYMLINK, MYF(0), linkname, content, errno);
  }
  DBUG_RETURN(result);
#endif /* HAVE_READLINK */
}
Example #18
0
t_env				*add_event(t_env *a, fct2 fct_read,
					   fct fct_write, int port)
{
  t_env				*result;
  t_env				*tmp;

  tmp = a;
  while (tmp->next)
    tmp = tmp->next;
  result = malloc(sizeof(t_env));
  if (result == NULL)
    my_error("Failed to malloc", 0);
  result->fct_read = fct_read;
  result->fct_write = fct_write;
  result->port = port;
  result->next = NULL;
  tmp->next = result;
  return (result);
}
Example #19
0
int my_mkdir(const char *dir, int Flags, myf MyFlags)
{
  DBUG_ENTER("my_dir");
  DBUG_PRINT("enter",("dir: %s",dir));

#if  defined(__WIN__)
  if (mkdir((char*) dir))
#else
  if (mkdir((char*) dir, Flags & my_umask_dir))
#endif
  {
    my_errno=errno;
    DBUG_PRINT("error",("error %d when creating direcory %s",my_errno,dir));
    if (MyFlags & (MY_FFNF | MY_FAE | MY_WME))
      my_error(EE_CANT_MKDIR,  MYF(ME_BELL+ME_WAITTANG), dir, my_errno);
    DBUG_RETURN(-1);
  }
  DBUG_RETURN(0);
}
Example #20
0
lr_train *mk_lr_train_from_dym( dym *factors, dyv *outputs, lr_options *opts)
{
  /* Set rows to NULL if you want all rows from ds to be used. */

  int numrows, numatts;
  lr_train *lrt;

  numrows = dym_rows( factors);
  numatts = dym_cols( factors)+1; /* Number of factors including constant. */

  /* Create lr lrt structure. */
  lrt = AM_MALLOC(lr_train);

  /* Copy in opts. */
  lrt->opts = mk_copy_lr_options( opts);

  /* Assign factors and outputs into lr structure. */
  lrt->X = NULL;
  lrt->M = factors;

  /* Outputs. */
  lrt->y = mk_copy_dyv( outputs);
  if (!dyv_is_binary( outputs)) {
    my_error( "mk_lr_train: Error: outputs are not binary.\n");
  }

  /* Set log likelihood of saturated model. */
  lrt->likesat = 0.0;

  /* Initialize remainder of lr struct */
  lrt->numatts = numatts;
  lrt->numrows = numrows;

  /* Create lr_state member. */
  lrt->lrs = mk_lr_state( lrt, opts);

  /* Now that the structure is complete, update n and u to prepare for
     iterations. */
  lr_train_update_n(lrt);
  lr_train_update_u(lrt);

  return lrt;
}
Example #21
0
void		check_reg2(char **args, int pos)
{
  int		i;
  int		nb;

  i = 2;
  while (args[i])
    {
      if (args[i][0] == 'r')
	{
	  args[i]++;
	  nb = my_getnbr(args[i]);
	  args[i]--;
	  if (1 > nb || nb > REG_NUMBER)
	    my_error(3, "No such register line", pos, "YOLO");
	}
      i++;
    }
}
Example #22
0
double roodof_t_xhi(double root_nu,double constant)
{
  double x = 1.0;
  bool ok = FALSE;
  int i;

  for ( i = 0 ; i < 50 && !ok ; i++ )
  {
    double pdf = roodof_t_h(root_nu,constant,x);
    if ( pdf < 1e-6 )
      ok = TRUE;
    else
      x *= 2;
  }

  if ( !ok ) my_error("tttttklaowidn");

  return(x);
}
Example #23
0
void			receive_pixels(t_client *client,
				       u_pixels *pixel_line)
{
  unsigned int		x;
  int			ret;

  x = 0;
  while (x < sizeof(pixel_line->pixelc))
    {
      ret = recv(client->csock, pixel_line->pixelc + x,
		 sizeof(pixel_line->pixelc) - x, 0);
      if (ret == sizeof(pixel_line->pixelc))
	break ;
      else if (ret >= 0)
	x += ret;
      else
	my_error("error: revc(): Failed.\n", 0);
    }
}
static
ds_ctxt_t *
local_init(const char *root)
{
	ds_ctxt_t *ctxt;

	if (my_mkdir(root, 0777, MYF(0)) < 0 && my_errno != EEXIST)
	{
		my_error(EE_CANT_MKDIR, MYF(ME_BELL | ME_WAITTANG),
			 root, my_errno);
		return NULL;
	}

	ctxt = my_malloc(sizeof(ds_ctxt_t), MYF(MY_FAE));

	ctxt->root = my_strdup(root, MYF(MY_FAE));

	return ctxt;
}
Example #25
0
SetPlayMode GetSPMForSpecSPM(SpecSetPlayMode spm)
{
  switch (spm) {
  case SSPM_No_Mode:
    return SPM_No_Mode;
  case SSPM_My_Kick_Off:
    return SPM_My_Kick_Off;
  case SSPM_Their_Kick_Off:
    return SPM_Their_Kick_Off;
  case SSPM_My_Kick_In_Def: 
  case SSPM_My_Kick_In_Mid:
  case SSPM_My_Kick_In_Off:
    return SPM_My_Kick_In;
  case SSPM_Their_Kick_In_Def:
  case SSPM_Their_Kick_In_Mid:
  case SSPM_Their_Kick_In_Off:
    return SPM_Their_Kick_In;
  case SSPM_My_Corner_Kick:
    return SPM_My_Corner_Kick;
  case SSPM_Their_Corner_Kick:
    return SPM_Their_Corner_Kick;
  case SSPM_My_Goal_Kick:
    return SPM_My_Goal_Kick;
  case SSPM_Their_Goal_Kick:
    return SPM_Their_Goal_Kick;
  case SSPM_My_Free_Kick_Upper:
  case SSPM_My_Free_Kick_Mid:
  case SSPM_My_Free_Kick_Lower:
    return SPM_My_Free_Kick;
  case SSPM_Their_Free_Kick_Upper:
  case SSPM_Their_Free_Kick_Mid:
  case SSPM_Their_Free_Kick_Lower:
    return SPM_Their_Free_Kick;
  case SSPM_My_Goalie_Catch:
    return SPM_My_Goalie_Catch;
  case SSPM_Their_Goalie_Catch:
    return SPM_Their_Goalie_Catch;
  default:
    my_error("What is SSPM: %d", spm);
    break;
  }
  return SPM_No_Mode;
}
Example #26
0
void* my_once_alloc(size_t Size, myf MyFlags)
{
  size_t get_size, max_left;
  uchar* point;
  reg1 USED_MEM *next;
  reg2 USED_MEM **prev;

  Size= ALIGN_SIZE(Size);
  prev= &my_once_root_block;
  max_left=0;
  for (next=my_once_root_block ; next && next->left < Size ; next= next->next)
  {
    if (next->left > max_left)
      max_left=next->left;
    prev= &next->next;
  }
  if (! next)
  {						/* Time to alloc new block */
    get_size= Size+ALIGN_SIZE(sizeof(USED_MEM));
    if (max_left*4 < my_once_extra && get_size < my_once_extra)
      get_size=my_once_extra;			/* Normal alloc */

    if ((next = (USED_MEM*) malloc(get_size)) == 0)
    {
      my_errno=errno;
      if (MyFlags & (MY_FAE+MY_WME))
	my_error(EE_OUTOFMEMORY, MYF(ME_BELL+ME_WAITTANG+ME_FATALERROR), get_size);
      return((uchar*) 0);
    }
    DBUG_PRINT("test",("my_once_malloc %lu byte malloced", (ulong) get_size));
    next->next= 0;
    next->size= get_size;
    next->left= get_size-ALIGN_SIZE(sizeof(USED_MEM));
    *prev=next;
  }
  point= (uchar*) ((char*) next+ (next->size-next->left));
  next->left-= Size;

  if (MyFlags & MY_ZEROFILL)
    memset(point, 0, Size);
  return((void*) point);
} /* my_once_alloc */
Example #27
0
int		coord_eyes(char **tab, int **coord)
{
  int		i;
  int		a;
  int		*c;

  i = 1;
  a = 0;
  c = xmalloc(sizeof(int) * 6);
  while (i <= 6)
    {
      if ((my_strlen(tab[i])) > 4)
	my_error("Please enter a valid coord\n");
      it_is_numbers(tab[i]);
      c[a++] = my_getnbr(tab[i++]);
    }
  *(coord) = copy_int_val(c, 6);
  free(c);
  return (i);
}
Example #28
0
File: my_bsq.c Project: plean/CPE
int	get_fnb(int fd)
{
    char	un[1];
    int	ret;
    int	nb;

    nb = 0;
    ret = read(fd, un, 1);
    while (ret != 0)
    {
        if (un[0] == '\n')
            return (nb);
        if (un[0] >= 48 && un[0] <= 57)
            nb = nb * 10 + un[0] - 48;
        else
            my_error();
        ret = read(fd, un, 1);
    }
    return (nb);
}
Example #29
0
void add_to_message(t_elem *client)
{
  int	sizeof_message;
  char	*new_message;
  char	c;
  char	*message;

  c = client->client_data.c;
  message = client->client_data.message;
  sizeof_message = my_strlen(client->client_data.message);
  if (!(new_message = my_strnew(sizeof_message + 1)))
    my_error(4, 7);
  if (client->client_data.message)
    my_strcpy(new_message, client->client_data.message);
  if (client->client_data.message)
    free(client->client_data.message);
  new_message[sizeof_message] = c;
  new_message[sizeof_message + 1] = 0;
  client->client_data.message = new_message;
}
Example #30
0
CHARSET_INFO *
my_collation_get_by_name(MY_CHARSET_LOADER *loader,
                         const char *name, myf flags)
{
  uint cs_number;
  CHARSET_INFO *cs;
  my_thread_once(&charsets_initialized, init_available_charsets);

  cs_number= get_collation_number(name);
  my_charset_loader_init_mysys(loader);
  cs= cs_number ? get_internal_charset(loader, cs_number, flags) : NULL;

  if (!cs && (flags & MY_WME))
  {
    char index_file[FN_REFLEN + sizeof(MY_CHARSET_INDEX)];
    my_stpcpy(get_charsets_dir(index_file),MY_CHARSET_INDEX);
    my_error(EE_UNKNOWN_COLLATION, MYF(0), name, index_file);
  }
  return cs;
}