Page 1 of 1

newlib question

Posted: Sat Aug 15, 2015 10:01 am
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])

Re: newlib question

Posted: Sat Aug 15, 2015 6:07 pm
by gerryg400
My first guess is that malloc is not working correctly. You will need to supply a working sbrk or similar for that.

Re: newlib question

Posted: Mon Aug 17, 2015 1:07 pm
by mcheung63
you are an expert, i finally find out my malloc is not working as expected. thanks