예제 #1
0
파일: utils.cpp 프로젝트: dfleury2/Nedit
// -------------------------------------------------------------------------
//  Part of the simple stack. Accepts a stack and the pointer you want to
//  store. NULL is not allowed, as it is used in Pop() to signal an empty
//  stack.
// -------------------------------------------------------------------------
void Push(Stack* stack, const void* value)
{
   stackObject* pushee;

   // Throw away invalid parameters.
   if (NULL == value)
   {
      fprintf(stderr, "nedit: Internal error: NULL was pushed.\n");
      return;
   }
   if (NULL == stack)
   {
      fprintf(stderr, "nedit: Internal error: push() called with NULL stack.\n");
      return;
   }

   //  Allocate memory for new value.
   pushee = (stackObject*) malloc__(sizeof(stackObject));

   //  Put pushee on top of stack.
   pushee->value = (void*) value;
   pushee->next = stack->top;
   stack->top = pushee;
   (stack->size)++;

   return;
}
예제 #2
0
파일: Debug.cpp 프로젝트: kjk/ars-framework
void* realloc__(void* p, size_t size, const char* file, int line)
{
    if (NULL != p && 0 == size)
    {
        free__(p);
        return NULL;
    }
    if (NULL == p)
        return malloc__(size, file, line);

#ifdef _PALM_OS

    if (errNone == MemPtrResize(p, size))
        return p;

    void* np = malloc__(size, file, line);
    if (NULL == np)
        return NULL;

    MemMove(np, p, MemPtrSize(p));
    free__(p);

#elif defined(_WIN32_WCE)

    void* np = realloc(p, size);
#ifndef NDEBUG    
    if (np != p)
    {
        logAllocation(p, 0, true, __FILE__, __LINE__);
        if (NULL != np)
            logAllocation(np, size, false, __FILE__, __LINE__);
    }
#endif    

#endif

    return np;
}
예제 #3
0
파일: utils.cpp 프로젝트: dfleury2/Nedit
// -------------------------------------------------------------------------
// Return a pointer to the username of the current user in a statically allocated string.
// -------------------------------------------------------------------------
const char* NeGetUserName()
{
   static char* userName = NULL;
#ifdef WIN32
   if (userName) return userName;

   userName = new char[MAXPATHLEN];
   userName[0] = '\0';
   const char* ptr = getenv("USERNAME");
    if (ptr)
      strncpy(userName, ptr, MAXPATHLEN-1);

    return userName;
#else
   // cuserid has apparently been dropped from the ansi C standard, and if
   // strict ansi compliance is turned on (on Sun anyhow, maybe others), calls
   // to cuserid fail to compile.  Older versions of nedit try to use the
   // getlogin call first, then if that fails, use getpwuid and getuid.  This
   // results in the user-name of the original terminal being used, which is
   // not correct when the user uses the su command.  Now, getpwuid only:

   const struct passwd* passwdEntry;

   if (userName)
      return userName;

   passwdEntry = getpwuid(getuid());
   if (!passwdEntry)
   {
      // This is really serious, but sometimes username service
      // is misconfigured through no fault of the user.  Be nice
      // and let the user start nc anyway.
      perror("nedit: getpwuid() failed - reverting to $USER");
      return getenv("USER");
   }
   else
   {
      userName=(char*)malloc__(strlen(passwdEntry->pw_name)+1);
      strcpy(userName, passwdEntry->pw_name);
      return userName;
   }
#endif
}
예제 #4
0
파일: Debug.cpp 프로젝트: kjk/ars-framework
void* malloc__(size_t size)
{
    return malloc__(size, __FILE__, __LINE__);
}