func nextGUID(isSystem bool) (db *dbfile, gid int, err error) {
	loadConfig()

	db, err = openDBFile(_GROUP_FILE, os.O_RDWR)
	if err != nil {
		return
	}

	// Seek to file half size.

	info, err := db.file.Stat()
	if err != nil {
		db.close()
		return nil, 0, err
	}
	if _, err = db.file.Seek(info.Size()/2, os.SEEK_SET); err != nil {
		db.close()
		return nil, 0, err
	}
	// To starting to read from a new line
	if _, _, err = db.rd.ReadLine(); err != nil {
		db.close()
		return nil, 0, err
	}

	var minGid, maxGid int
	if isSystem {
		minGid, maxGid = config.login.SYS_GID_MIN, config.login.SYS_GID_MAX
	} else {
		minGid, maxGid = config.login.GID_MIN, config.login.GID_MAX
	}

	for {
		line, _, err := db.rd.ReadLine()
		if err == io.EOF {
			break
		}

		gr, err := parseGroup(string(line))
		if err != nil {
			db.close()
			return nil, 0, err
		}
		if gr.GID >= minGid && gr.GID <= maxGid {
			gid = gr.GID
		}
	}

	gid++
	if gid == maxGid {
		return nil, 0, &IdRangeError{maxGid, isSystem, false}
	}
	return
}
func nextGUID(isSystem bool) (db *dbfile, gid int, err error) {
	loadConfig()

	db, err = openDBFile(_GROUP_FILE, os.O_RDWR)
	if err != nil {
		return
	}

	

	info, err := db.file.Stat()
	if err != nil {
		db.close()
		return nil, 0, err
	}
	if _, err = db.file.Seek(info.Size()/2, os.SEEK_SET); err != nil {
		db.close()
		return nil, 0, err
	}
	
	if _, _, err = db.rd.ReadLine(); err != nil {
		db.close()
		return nil, 0, err
	}

	var minGid, maxGid int
	if isSystem {
		minGid, maxGid = config.login.SYS_GID_MIN, config.login.SYS_GID_MAX
	} else {
		minGid, maxGid = config.login.GID_MIN, config.login.GID_MAX
	}

	for {
		line, _, err := db.rd.ReadLine()
		if err == io.EOF {
			break
		}

		gr, err := parseGroup(string(line))
		if err != nil {
			db.close()
			return nil, 0, err
		}
		if gr.GID >= minGid && gr.GID <= maxGid {
			gid = gr.GID
		}
	}

	gid++
	if gid == maxGid {
		return nil, 0, &IdRangeError{maxGid, isSystem, false}
	}
	return
}
func nextGUID ( isSystem bool ) ( db * dbfile , gid int , err error ) { loadConfig ( ) db , err = openDBFile ( _GROUP_FILE , os . O_RDWR ) if err != nil { return } // Seek to file half size. info , err := db . file . Stat ( ) if err != nil { db . close ( ) return nil , 0 , err } if _ , err = db . file . Seek ( info . Size ( ) / 2 , os . SEEK_SET ) ; err != nil { db . close ( ) return nil , 0 , err } // To starting to read from a new line if _ , _ , err = db . rd . ReadLine ( ) ; err != nil { db . close ( ) return nil , 0 , err } var minGid , maxGid int if isSystem { minGid , maxGid = config . login . SYS_GID_MIN , config . login . SYS_GID_MAX } else { minGid , maxGid = config . login . GID_MIN , config . login . GID_MAX } for { line , _ , err := db . rd . ReadLine ( ) if err == io . EOF { break } gr , err := parseGroup ( string ( line ) ) if err != nil { db . close ( ) return nil , 0 , err } if gr . GID >= minGid && gr . GID <= maxGid { gid = gr . GID } } gid ++ if gid == maxGid { return nil , 0 , & IdRangeError { maxGid , isSystem , false } } return }
// nextGUID returns the next free group id to use, according to whether it is a
// system's group.
nextGUID returns the next free group id to use according to whether it is a system s group .