Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

To be a kind of moral Unix, he touched the hem of Nature's shift. -- Shelley


devel / comp.lang.c / bytes.c

SubjectAuthor
* bytes.cfir
`- Re: bytes.cfir

1
bytes.c

<uu9t5m$3ii8t$1@i2pn2.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=34879&group=comp.lang.c#34879

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!.POSTED!not-for-mail
From: fir...@grunge.pl (fir)
Newsgroups: comp.lang.c
Subject: bytes.c
Date: Sat, 30 Mar 2024 21:37:15 +0100
Organization: i2pn2 (i2pn.org)
Message-ID: <uu9t5m$3ii8t$1@i2pn2.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 30 Mar 2024 20:37:11 -0000 (UTC)
Injection-Info: i2pn2.org;
logging-data="3754269"; mail-complaints-to="usenet@i2pn2.org";
posting-account="+ydHcGjgSeBt3Wz3WTfKefUptpAWaXduqfw5xdfsuS0";
User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:27.0) Gecko/20100101 Firefox/27.0 SeaMonkey/2.24
X-Spam-Checker-Version: SpamAssassin 4.0.0
 by: fir - Sat, 30 Mar 2024 20:37 UTC

it is not bad idea to write bytes.c file having methods for this
microcontainer (same as ints.c floats.c literals.c etc) (all as a part
of sickle.c c library)

the idea seems good becouse back then i was writing methods for
"chunk", and "chybaks" and it was not celar what it should
contain - now as bytes.c are simpler the answer what to put there is
simpler and thats good

(sadly im feeling old and yet few years ago if i get that idea i found
it very
interesting to work on thit right now i know its interesting but
not find it so much interesting on 'physical level' as i get tired
and bored of everything (more tired and rotten than bored in fact)

few initial methods on this how it would look like

#include <sys/stat.h>

int GetFileSize2(char *filename)
{
struct stat st;
if (stat(filename, &st)==0) return (int) st.st_size;
ERROR_EXIT("error obtaining file size for %s", filename);
return -1;
}

///////////////bytes container
unsigned char* bytes = NULL;
int bytes_size = 0;
int bytes_allocked = 0;

void bytes_add_(unsigned char val) { (bytes=(unsigned
char*)realloc(bytes,++bytes_size*sizeof(unsigned
char)))[bytes_size-1]=val; }

char* bytes_resize(int size)
{
bytes_size=size;
if((bytes_size+100)*2<bytes_allocked | bytes_size>bytes_allocked)
return bytes=(unsigned char*)realloc(bytes,
(bytes_allocked=(bytes_size+100)*2)*sizeof(unsigned char));
}

void bytes_add(unsigned char val)
{
if(++bytes_size>bytes_allocked)
bytes=(unsigned char*)realloc(bytes,
(bytes_allocked=(bytes_size+100)*2)*sizeof(unsigned char));
bytes[bytes_size-1]=val;
return;
}

//////////////////

void bytes_load(char* name)
{
int flen = GetFileSize2(name);
FILE *f = fopen(name, "rb");
if(!f) ERROR_EXIT( "errot: cannot open file %s ", name);
int loaded = fread(bytes_resize(flen), 1, flen, f);
fclose(f);
}

void bytes_save(char* name)
{
FILE* f =fopen(name, "wb");
int saved = fwrite (bytes , 1, bytes_size, f);
fclose (f);
}

////////////////

void bytes_dump_in_hex()
{
for(int i=0; i<bytes_size; i++)
{
if(!(i%16)) printf("\n");

printf("%02x ", bytes[i]);
}
}

void bytes_init(unsigned char (*init_predicate)(int ) )
{
for(int i=0; i<bytes_size;i++)
bytes[i] = init_predicate(i);
}

////////////////////

unsigned char ini2(int i) { return i&0xff; }

void BytesTest()
{
bytes_resize(1000);
bytes_init(ini2);
bytes_dump_in_hex();

// bytes_resize(100);
// bytes_dump_in_hex();

}

Re: bytes.c

<uu9tho$3iiog$1@i2pn2.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=34880&group=comp.lang.c#34880

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!.POSTED!not-for-mail
From: fir...@grunge.pl (fir)
Newsgroups: comp.lang.c
Subject: Re: bytes.c
Date: Sat, 30 Mar 2024 21:43:41 +0100
Organization: i2pn2 (i2pn.org)
Message-ID: <uu9tho$3iiog$1@i2pn2.org>
References: <uu9t5m$3ii8t$1@i2pn2.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 30 Mar 2024 20:43:37 -0000 (UTC)
Injection-Info: i2pn2.org;
logging-data="3754768"; mail-complaints-to="usenet@i2pn2.org";
posting-account="+ydHcGjgSeBt3Wz3WTfKefUptpAWaXduqfw5xdfsuS0";
User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:27.0) Gecko/20100101 Firefox/27.0 SeaMonkey/2.24
X-Spam-Checker-Version: SpamAssassin 4.0.0
In-Reply-To: <uu9t5m$3ii8t$1@i2pn2.org>
 by: fir - Sat, 30 Mar 2024 20:43 UTC

fir wrote:
> it is not bad idea to write bytes.c file having methods for this
> microcontainer (same as ints.c floats.c literals.c etc) (all as a part
> of sickle.c c library)
>
> the idea seems good becouse back then i was writing methods for
> "chunk", and "chybaks" and it was not celar what it should
> contain - now as bytes.c are simpler the answer what to put there is
> simpler and thats good
>

you may say what methods may be handy as i may overlook some

- and note i wouldnt say people know that approach (method) in c,
if they would there would be such knotainers famous (well known) imo
as their are handy tools for c coding imo 0 increasing speed of coding
and readibility of codes also

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor