Beispiel #1
0
int task1( int dummy0, int dummy1, int dummy2, int dummy3, int dummy4,
           int dummy5, int dummy6, int dummy7, int dummy8, int dummy9 )
{

STATUS err;
int i;
char *buffer;

taskDelay( 50 );

for (;;) {
    puts( "\r\ntask1 waiting for ready signal from either of SEM2 or SEM3" );

    err = semTake( sema42_id, NO_WAIT );
    if ( err == OK )
    {
        /*
        **  Received ready signal from task 2...
        */
        buffer = ts_malloc( 128 );
        if ( buffer != (char *)NULL )
        {
            for (i = 0; i < 10; i++)
                buffer[i] = 'A' + i;
            buffer[i] = 0;

            printf("\r\ntask1's message for task2: %s\n", buffer );

            err = msgQSend( queue2_id, buffer, 11, NO_WAIT, MSG_PRI_NORMAL );
            ts_free( buffer );
        }
        else
            puts( "\r\nNo memory for message to task 2" );
    }

    err = semTake( sema43_id, NO_WAIT );
    if ( err == OK )
    {
        /*
        **  Received ready signal from task 3...
        */
        buffer = ts_malloc( 128 );
        if ( buffer != (char *)NULL )
        {
            for (i = 0; i < 10; i++)
                buffer[i] = 'Z' - i;
            buffer[i] = 0;

            printf("\r\ntask1's message for task3: %s\n", buffer );

            err = msgQSend( queue3_id, buffer, 11, NO_WAIT, MSG_PRI_NORMAL );
            ts_free( buffer );
        }
        else
            puts( "\r\nNo memory for message to task 3" );
    }

    taskDelay( 1 );
  }
}
Beispiel #2
0
schar ts_log_init(void)
{
	tsh->log=(TS_Log *)ts_malloc(sizeof(struct TS_Log));
	if (tsh->log==NULL) return TS_ERROR;
	tsh->log->log_filename=(char *)ts_malloc(TS_MAX_STRING);
	if (tsh->log->log_filename==NULL) return TS_ERROR;
	tsh->log->log_on=TS_LOG;
	strcpy(tsh->log->log_filename,tsh->program_name);
	strcat(tsh->log->log_filename,".log");
	return TS_OK;
}
Beispiel #3
0
void	prompt_update(t_system *system)
{
  char	*buf;
  int	it;

  it = 0;
  free(g_prompt.prompt);
  buf = utl_itoa(g_prompt.line_count);
  system->env = env_set(system->env, "LINE_COUNT", buf);
  free(buf);
  if ((g_prompt.prompt = ts_malloc(prompt_get_size(system) + 1)))
    {
      it = 0;
      g_prompt.prompt[0] = '\0';
      while (g_prompt.format[it])
	{
	  if (g_prompt.format[it] == VARIABLE_CHAR)
	    {
	      utl_strcat(g_prompt.prompt,
			 env_parsevar(system->env, g_prompt.format + it));
	      it += get_total_varlen(g_prompt.format + it);
	    }
	  else
	    utl_strcatc(g_prompt.prompt, g_prompt.format[it++]);
	}
    }
}
Beispiel #4
0
int main(int argc, char **argv) {
    void *p = ts_malloc(10);
    printf("%p, remain %zu\n", p, ts_get_total_size());
    ts_free(p);
    printf("remain %zu\n", ts_get_total_size());
    return 0;
}
Beispiel #5
0
void	*tcs_type_int32(char *data)
{
  void	*rtn;

  if ((rtn = ts_malloc(4)) == NULL)
    return (NULL);
  return (ts_memcpy(data, rtn, 4));
}
Beispiel #6
0
static struct ts_crypto_ctx *ts_crypto_plain() {
    struct ts_crypto_ctx *ctx = ts_malloc(sizeof(struct ts_crypto_ctx));
    if (ctx) {
        ctx->encrypt = ts_plain_crypto;
        ctx->decrypt = ts_plain_crypto;
    }
    return ctx;
}
Beispiel #7
0
char	*tcs_wtype_int32(void *data)
{
  char	*rtn;

  if ((rtn = ts_malloc(4)) == NULL)
    return (NULL);
  ts_memcpy(data, rtn, 4);
  return (rtn);
}
Beispiel #8
0
static struct ts_crypto_ctx *ts_crypto_sstable(const uint8_t *key, int len) {
    struct ts_crypto_ctx *ctx = ts_malloc(sizeof(struct ts_crypto_ctx));
    if (ctx) {
        sstable_init(&ctx->sstable, key, len);
        ctx->encrypt = ts_sstable_encrypt;
        ctx->decrypt = ts_sstable_decrypt;
    }
    return ctx;
}
Beispiel #9
0
static struct ts_crypto_ctx *ts_crypto_rc4(const unsigned char *key, int len) {
    struct ts_crypto_ctx *ctx = ts_malloc(sizeof(struct ts_crypto_ctx));
    if (ctx) {
        rc4_init(&ctx->rc4.enc_state, key, len);
        rc4_init(&ctx->rc4.dec_state, key, len);
        ctx->encrypt = ts_rc4_encrypt;
        ctx->decrypt = ts_rc4_decrypt;
    }
    return ctx;
}
Beispiel #10
0
/*
** /!\ this function is using sizeof, data must be malloc'd (should not be a
** problem with tcs reader)
*/
void	*tcs_type_ascii(char *data)
{
  char	*rtn;
  int	size;

  size = sizeof(data);
  if ((rtn = ts_malloc(size + 1)) == NULL)
    return (NULL);
  rtn = ts_memcpy(data, rtn, size);
  rtn[size] = '\0';
  return (rtn);
}
Beispiel #11
0
char	*utl_strncpy(char *str, int n)
{
  char	*rtn;
  int	it;

  if ((rtn = ts_malloc((n + 1) * sizeof(char))) == NULL)
    return (NULL);
  it = 0;
  while (it < n)
    {
      rtn[it] = str[it];
      it++;
    }
  rtn[it] = '\0';
  return (rtn);
}
Beispiel #12
0
char	*tcs_read_ascii(t_file *file)
{
  short	size;
  int	it;
  char	*rtn;

  size = 0;
  read_data(file, &size, 2);
  if ((rtn = ts_malloc(size + 1)) == NULL)
    return (NULL);
  it = 0;
  while (it < size)
    rtn[it++] = read_char(file);
  rtn[it] = '\0';
  return (rtn);
}
Beispiel #13
0
static char	*get_rc_path(t_system *system)
{
  char		*rtn;
  char		*home;

  home = env_get(system->env, "HOME");
  if (home)
    {
      rtn = ts_malloc(utl_strlen(home) + utl_strlen("/.swagrc") + 1);
      if (!rtn)
	return (NULL);
      rtn[0] = '\0';
      utl_strcat(rtn, home);
      utl_strcat(rtn, "/.swagrc");
      return (rtn);
    }
  return (NULL);
}
void* tsmCreate()
{
	TSM_OBJ* pObj=NULL;
	void* ptr=NULL;

	//malloc memory for object
	pObj=(TSM_OBJ*)ts_malloc(sizeof(TSM_OBJ));
	if(pObj==NULL){
		TS_ERROR("%s: error: malloc %d bytes fail \n",__FUNCTION__,sizeof(TSM_OBJ));
		return NULL;
	}
	ts_memset((void*)pObj, 0, sizeof(TSM_OBJ));

#ifndef TS_DIS_ORI_TSMANAGER
	//create original ts manager
	TS_API("ori:calling createTSManager(%d) \n",TS_LIST_LEN);
	ptr=createTSManager(TS_LIST_LEN);
	if(ptr){
		pObj->pHandleOri=ptr;
		pObj->nInTsCntOri=0;
		pObj->nInCurTsOri=TS_INVALIDTS;
	}
	else	{
		goto TSM_Create_Fail;
	}
#endif

#ifndef TS_DIS_NEW_TSMANAGER
	//create new ts manager
	TS_API("new:calling createTSManager(%d) \n",TS_LIST_LEN);
	ptr=createTSManager(TS_LIST_LEN);
	if(ptr){
		pObj->pHandle2=ptr;
		pObj->nInTsCnt2=0;
		pObj->nInCurTs2=TS_INVALIDTS;
		pObj->nCurInputTs=TS_INVALIDTS;
		pObj->nCurOutputTs=TS_INVALIDTS;
	}
	else	{
		goto TSM_Create_Fail;
	}
#endif

	//set default value
	pObj->nLastTs=TS_INVALIDTS;
	pObj->nDeltaTs=TS_INVALIDTS;
	pObj->nDurationMsThr=TS_THRESHOLD_DURATION_INVALID;
	pObj->nBlkCntThr=TS_THRESHOLD_BLKCNT_INVALID;
	return (void*)pObj;

TSM_Create_Fail:
	if(pObj->pHandleOri){
		TS_API("ori:calling destroyTSManager \n");
		destroyTSManager(pObj->pHandleOri);
		pObj->pHandleOri=NULL;
	}
	if(pObj->pHandle2){
		TS_API("new:calling destroyTSManager \n");
		destroyTSManager(pObj->pHandle2);
		pObj->pHandle2=NULL;
	}
	if(pObj){
		ts_free(pObj);
	}
	return NULL;
}