Plan 9 from Bell Labs’s /usr/web/sources/contrib/fernan/nhc98/src/runtime/Mk/mkPackedString.c

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


#include <string.h>
#include "mk.h"

int nhc_sizePackedString(int length)
{
  int size = (length + sizeof(Node) -1) / sizeof(Node);
  return (1+EXTRA+size);
}


NodePtr nhc_allocPackedString(int length)
{
  NodePtr n;
  int size = (length + sizeof(Node) -1) / sizeof(Node);
  int extra = size * sizeof(Node) - length;

  n = C_ALLOC(1+EXTRA+size);
  *n = CONSTRW(size,extra);
  INIT_PROFINFO(n,&dummyProfInfo)
  return n;
}

void nhc_copyPackedString(int length, NodePtr dst, char *src)
{
  if (src==(char*)0)
    memcpy((char*)&dst[1+EXTRA],"\0",1);
  else
    memcpy((char*)&dst[1+EXTRA],src,length);
}

NodePtr nhc_mkPackedString(int length, char *str)
{
  NodePtr n = nhc_allocPackedString(length);
  nhc_copyPackedString(length,n,str);
  return n;
}

char *nhc_getPackedString(NodePtr n)
{
  return (char*)&n[1+EXTRA];
}








Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.