amath  1.8.5
Simple command line calculator
alloccpy.c File Reference
#include "amathc.h"
Include dependency graph for alloccpy.c:

Go to the source code of this file.

Functions

unsigned int AllocAndCopy (char **destination, const char *source)
 Allocate memory and copy a string into the array. More...
 

Function Documentation

◆ AllocAndCopy()

unsigned int AllocAndCopy ( char **  destination,
const char *  source 
)

Allocate memory and copy a string into the array.

Definition at line 40 of file alloccpy.c.

Referenced by AnsiConoleEngine::AnsiConoleEngine(), CharBuffer::ClearAndCopy(), ConsoleBase::ConsoleBase(), AnsiConoleEngine::CopyLine(), DeleteStatement::DeleteStatement(), DrawStatement::DrawStatement(), ErrorNode::ErrorNode(), ExecuteStatement::ExecuteStatement(), FunctionNode::FunctionNode(), HelpStatement::HelpStatement(), Lexer::Lexer(), ListStatement::ListStatement(), StandardLanguage::LoadCatalog(), LoadStatement::LoadStatement(), PlotStatement::PlotStatement(), PromptStatement::PromptStatement(), SaveStatement::SaveStatement(), PreferencesBase::SetDefaults(), PreferencesBase::SetPrompt(), AnsiConoleEngine::SetPrompt(), ConsoleBase::SetPrompt(), AnsiConoleEngine::ShowLast(), ShowStatement::ShowStatement(), StatementNode::StatementNode(), Token::Token(), UserFunction::UserFunction(), and Variable::Variable().

41 {
42  char *i, *s, *d;
43  unsigned int n, size;
44 
45  if (source == nullptr)
46  {
47  *destination = nullptr;
48  return 0;
49  }
50 
51  i = (char*)source;
52  s = (char*)source;
53  while (*i)
54  i++;
55 
56  n = (unsigned int)(i - s + 1);
57  size = n;
58  *destination = AllocMemSafe(size);
59  d = *destination;
60 
61 #if defined(AMIGA) // Take advantage of exec
62  CopyMem(s, d, n);
63 #else
64  while (n--)
65  *d++ = *s++;
66 #endif
67 
68  return size;
69 }
size_t size
Definition: mem.c:60
void * AllocMemSafe(size_t)
Allocate memory and add it to the global memory list.
Definition: mem.c:86
Here is the caller graph for this function: