newlib question

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
mcheung63
Member
Member
Posts: 175
Joined: Thu Jun 22, 2006 8:33 am
Location: Hong Kong
Contact:

newlib question

Post by mcheung63 »

Hi All
I got an issue using newlib. here is the __sfp function, when i can fopen, it jump to here :

FILE *
_DEFUN(__sfp, (d),
struct _reent *d){
FILE *fp;
int n;
struct _glue *g;

_newlib_sfp_lock_start ();

if (!_GLOBAL_REENT->__sdidinit)
__sinit (_GLOBAL_REENT);
for (g = &_GLOBAL_REENT->__sglue;; g = g->_next)
{
for (fp = g->_iobs, n = g->_niobs; --n >= 0; fp++) {
printf("fp->_flags=%d\n",fp->_flags);
if (fp->_flags == 0) {
goto found;
}
}
if (g->_next == NULL &&
(g->_next = __sfmoreglue (d, NDYNAMIC)) == NULL)
break;
}

__asm __volatile__("XCHG %BX, %BX");
_newlib_sfp_lock_exit ();
d->_errno = ENOMEM;
return NULL;


I can't open a file, unless i change "s->__sglue._niobs = 3;" to "s->__sglue._niobs = 999;" manually in __sinit function.

Am i doing it correctly?

thanks
from Peter ([email protected])
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: newlib question

Post by gerryg400 »

My first guess is that malloc is not working correctly. You will need to supply a working sbrk or similar for that.
If a trainstation is where trains stop, what is a workstation ?
User avatar
mcheung63
Member
Member
Posts: 175
Joined: Thu Jun 22, 2006 8:33 am
Location: Hong Kong
Contact:

Re: newlib question

Post by mcheung63 »

you are an expert, i finally find out my malloc is not working as expected. thanks
Post Reply